LB Booster
Programming >> Liberty BASIC language >> LEN function different in LBB and LB
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1487201052

LEN function different in LBB and LB
Post by Argand on Feb 15th, 2017, 10:24pm

I notice that the LEN function in LBB is different to LB. For example the code for the string " x ", i.e. (two spaces,x,two spaces) below

PROMPT "type a string:"; string$
TotalLength = LEN(string$)
PRINT "The total number of characters in your string is :" ;
PRINT TotalLength
END

gives 5 in LBB but gives 1 in LB. So LBB counts spaces as well as letters and numbers.
Re: LEN function different in LBB and LB
Post by CirothUngol on Feb 16th, 2017, 01:51am

It's not the LEN() function, it's the PROMPT command. Try the following Code:
PROMPT "type a string:"; string$
string2$ = "  x  "
TotalLength = LEN(string$)
OtherLength = LEN(string2$)
PRINT "The total number of characters in your string is :" ; TotalLength
PRINT "The total number of characters in the other string is :" ; OtherLength
END 
Apparently, LB does an automatic TRIM$() to remove any leading or trialing white space from PROMPT. I would be more inclined to consider it an error in LB, to be honest. I'll TRIM$() my own input, thank you. ^_^
Re: LEN function different in LBB and LB
Post by Richard Russell on Feb 16th, 2017, 09:56am

on Feb 16th, 2017, 01:51am, CirothUngol wrote:
Apparently, LB does an automatic TRIM$() to remove any leading or trialing white space from PROMPT.

Interesting. I've never noticed it, no doubt because typing leading and/or trailing spaces in response to a PROMPT isn't particularly 'natural'. LBB could easily be changed of course, but it would reduce flexibility and as you say adding an explicit TRIM$() in your program is straightforward.

So I'm inclined to leave it as it is, but something to be borne in mind.

Richard.