Oxygen Basic
Programming => Problems & Solutions => Topic started by: chrisc on March 21, 2018, 05:55:10 PM
-
In PB, we have a ubiquitous TRIM$ function which can remove hidden or null characters from a string
such as CHR$(0) , CHR$(32), CHR$(10) , CHR$(13), CHR$(9) as shown below
' Trim off all nulls and hidden characters from the string givenst
givenst = TRIM$(givenst,ANY CHR$(0) + CHR$(32)+ CHR$(10) + CHR$(13)+ CHR$(9))
is there a way to do this in O2 ?
i have tried LTRIM and RTRIM but they cannot remove the nulls and other hidden charcters
-
Hi Chris,
ltrim(rtrim(s)) will trim all your white space
'2018-03-22 T 05:25:18
'TRIM WHITE SPACE
uses console
string s=nuls(1) cr tab " q " cr tab nuls(1)
's=ltrim rtrim s
printl len s
s=ltrim s
printl len s
s=rtrim s
printl len s
wait
-
Thanxx a lot Charles
i have added + CHR(32)+ CHR(10) + CHR(13)+ CHR(9) to check and it does trim off everything
'2018-03-22 T 05:25:18
'TRIM WHITE SPACE
uses console
string s=nuls(1) cr tab " q " cr tab nuls(1) + CHR(32)+ CHR(10) + CHR(13)+ CHR(9)
's=ltrim rtrim s
printl " S : " + s
printl " Length before "
printl len s
printl " "
s=ltrim s
printl len s
s=rtrim s
printl " Length after "
printl len s
printl " S : " + s
wait
therefore does s=ltrim rtrim s is equivalent to PB's TRIM$() function ?
-
Yes, Chris
you can define it:
def trim ltrim(rtrim(%1))
-
Thanxx