Author Topic: Equivalent of PB Trim$() function  (Read 1273 times)

0 Members and 1 Guest are viewing this topic.

chrisc

  • Guest
Equivalent of PB Trim$() function
« 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

Code: [Select]
'      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


Charles Pegge

  • Guest
Re: Equivalent of PB Trim$() function
« Reply #1 on: March 21, 2018, 09:35:15 PM »
Hi Chris,

ltrim(rtrim(s)) will trim all your white space

Code: [Select]
'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


chrisc

  • Guest
Re: Equivalent of PB Trim$() function
« Reply #2 on: March 22, 2018, 06:52:09 AM »
Thanxx a lot Charles

i have added  + CHR(32)+ CHR(10) + CHR(13)+ CHR(9)  to check and it does trim off everything


Code: [Select]
'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 ?
 


Charles Pegge

  • Guest
Re: Equivalent of PB Trim$() function
« Reply #3 on: March 22, 2018, 07:53:12 AM »
Yes, Chris

you can define it:

Code: [Select]
def trim ltrim(rtrim(%1))

chrisc

  • Guest
Re: Equivalent of PB Trim$() function
« Reply #4 on: March 22, 2018, 07:56:32 AM »
Thanxx