Can't get TRIM$() nor replstr$() to work

Discussions about the Liberty BASIC language, with particular reference to LB Booster
flotul
Posts: 12
Joined: Fri Apr 06, 2018 7:06 am

Can't get TRIM$() nor replstr$() to work

Post by flotul »

Hi,

Either code will give me the expected result I'd like to see: "1,2,3".

Code: Select all

DECString$ = "  1,  2,  3"
DECString$ = TRIM$(DECString$)
print DECString$

result: "  1,  2,  3"

Code: Select all

DECString$ = "  1,  2,  3"
DECString$ = replstr$(DECString$, " ", "")
print DECString$

'include lb45func.bas

result: "  1,  2,  3"
What am I missing/doing wrong please?
flotul
Posts: 12
Joined: Fri Apr 06, 2018 7:06 am

Re: Can't get TRIM$() nor replstr$() to work

Post by flotul »

My bad,

Using TRIM$(), the result is "1, 2, 3" (not " 1, 2, 3") wich is correct.

Still, replstr$() doesn't accept to replace a character by "nothing".

What is the best way to remove any space in a full string then?
guest
Site Admin
Posts: 197
Joined: Tue Apr 03, 2018 1:34 pm

Re: Can't get TRIM$() nor replstr$() to work

Post by guest »

flotul wrote: Wed Sep 14, 2022 4:06 pm Still, replstr$() doesn't accept to replace a character by "nothing".
It seems to work for me. I tried this program:

Code: Select all

print chr$(34); replstr$("Hello world!", "o", ""); chr$(34)
'include lb45func.bas
And it produced the output "Hell wrld!" which is correct, isn't it?
What is the best way to remove any space in a full string then?
Again it seems to work for me:

Code: Select all

print chr$(34); replstr$("Hello world!", " ", ""); chr$(34)
'include lb45func.bas
which produced "Helloworld!". I can't understand why it is seemingly working for me but not for you. What happens if you try the exact examples listed above?
flotul
Posts: 12
Joined: Fri Apr 06, 2018 7:06 am

Re: Can't get TRIM$() nor replstr$() to work

Post by flotul »

Hi,

Yes, this works!

Code: Select all

print chr$(34); replstr$("Hello world!", "o", ""); chr$(34)
'include lb45func.bas
But why won't this one do too?

Code: Select all

print chr$(34); replstr$("  1  2  3", " ", ""); chr$(34)
'include lb45func.bas
At least, it doesn't for me....
flotul
Posts: 12
Joined: Fri Apr 06, 2018 7:06 am

Re: Can't get TRIM$() nor replstr$() to work

Post by flotul »

...just learned about the remchar$() that will do the job for me.

Didn't think about this one - never used before... :?