Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Declaring the length of a string
#1
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:
Code:
10 DIM a$="hello"
20 DIM b$(8)
30 LET b$=a$
40 LET b$(4 TO 8)="p me!"
50 PRINT b$

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?
Reply


Messages In This Thread
Declaring the length of a string - by patters - 01-03-2021, 01:55 AM
RE: Declaring the length of a string - by boriel - 01-03-2021, 11:01 AM
RE: Declaring the length of a string - by patters - 01-03-2021, 06:09 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)