LEFT$() and RIGHT$() assignment
Posted: Mon Oct 09, 2023 5:40 pm
hello everyone, and welcome!
I'm trying to tidy up the manual before releasing the new version of ugBASIC (v1.15) and I found myself faced with a rather questionable implementation of the LEFT$(..) and RIGHT$(..) commands.
I'll try to explain better.
In general, BASIC has facilities for extracting substrings from a string. For example,
However, some BASIC (e.g. AMOS) also has a LEFT instruction:
Now, it is clear that some limits must be set. But which ones? For example, if in the previous example the string to be replaced was more than 3 characters long, what should ugBASIC do? What if the string a$ is shorter than 3 characters? I need some advice on smart implementation.
For those who are curious... to date the assignment only works if the string to be replaced is as long as the numeric parameter of LEFT$(..) / RIGHT$(..).
I'm trying to tidy up the manual before releasing the new version of ugBASIC (v1.15) and I found myself faced with a rather questionable implementation of the LEFT$(..) and RIGHT$(..) commands.
I'll try to explain better.
In general, BASIC has facilities for extracting substrings from a string. For example,
Code: Select all
a$ = LEFT$("pippo", 3) : PRINT a$: REM prints "pip"
Code: Select all
a$ = "punto": LEFT$(a$, 3) = "plu": PRINT a$: REM prints "pluto"
For those who are curious... to date the assignment only works if the string to be replaced is as long as the numeric parameter of LEFT$(..) / RIGHT$(..).