to join MID$ - these commands take the rightmost (or leftmost) characters from a string - very useful for leading zeroes - for example
PRINT "Score: "+RIGHT$("000000"+score,6)
would take the last 6 characters of the string, giving:
Score: 000007
Score: 000042
Score: 012345
Hi PeeJay,
I've wrote this function for you
// --------------------------------- //
// Project: TESTZERO$
// Start: Monday, January 14, 2008
// IDE Version: 5.129
score = 1966
PRINT zero$(score,10,TRUE),10,10
PRINT zero$(score,8,FALSE),10,20
SHOWSCREEN
KEYWAIT
// ------------------------------------------------------------- //
// --- ZERO$ ---
// ------------------------------------------------------------- //
FUNCTION zero$: wnum, wlen, wlor //wlor= FALSE = Left - TRUE = Right
LOCAL wi,wnlen,wstr$,wzero$
wstr$ = wnum
wnlen = LEN(wstr$)
IF wnlen < wlen
FOR wi = 0 TO (wlen - wnlen - 1)
wzero$ = wzero$ + "0"
NEXT
IF wlor = TRUE
RETURN wzero$+wstr$
ELSE
RETURN wstr$+wzero$
ENDIF
ELSE
RETURN wstr$
ENDIF
ENDFUNCTION // ZERO$
Bye bye,
Neurox
Thanks Neurox - that is great for this, but I still think they are very useful commands for string splicing, for word wrap and the like
FUNCTION RIGHT$: str$, l
RETURN MID$(str$,LEN(str$) - l, l)
ENDFUNCTION
FUNCTION LEFT$: str$, l
RETURN MID$(str$,0,l)
ENDFUNCTION
P.S. thats a lowercase 'L' not a 1, in the function parameter.
Instead of 'l' I usually type "lng"
Could MID$ accept negative parameter (counting from end of string instead of begining)?
another suggestion: NOT and XOR operators (on true/false values): eg. IF NOT myboolean THEN ...