(01-03-2021, 01:55 AM)patters Wrote: In Sinclair BASIC you can DIM the length of a string using
DIM a$(5)
If I try something similar in Boriel BASIC
DIM a$(5) AS STRING
the compiler seems to interpret this as an array declaration.
Sometimes it's useful to declare the largest expected length of a string if you want to build it up of component pieces. e.g. In Sinclair BASIC:
...
If I try to do this in Boriel BASIC I can't declare the length, nor does it expand when needed. I seem to have to do it in two steps, one for overwriting the parts of the existing string, and a separate step to glue an addition to the end of the string.
Code:DIM a$, b$
a$="hello"
b$=a$
b$(3 TO 4)="p "
b$=b$+"me!"
PRINT b$
Is this expected? Or is there a better way of building b$ from a$ in this example in only one step?
This is expected. For speed reasons, DIM is always used for ARRAYS. There's no way to limit string length in ZXBasic.
Updating a substring is done like in Sinclair BASIC ("procrustean method"), so the length of the string does not change.
You can do it all in a single sentence in most cases:
Code:
DIM a$, b$
a$="hello"
b$=a$(TO 2) + "p me!"
PRINT b$
Also, if you're using Sinclair BASIC features, there is a compatibility flag, --sinclair which will do the following:
- Arrays will start at position 1 by default, not 0
- Strings will start at position 1, not 0
- Booleans are always 0 or 1 (otherwise they will be 0 = False, Any other value = True)
- Will include extra functions (ATTR, POINT), that won't be compiled if not used.
I suggest you to use these if you're starting with ZX Basic until you're familiarized with it.
READ, DATA and RESTORE are available too.