DIM symbolname$ ( maxlength ) ' kept for
backward compatibility
or
DIM symbolname ( maxlength ) AS
STRING
A STRING is an array of characters, and is limited to 256
characters. Larger strings may be allocated, but string operations should
be limited to the first 256 characters (no runtime check).
Despite the
use of the maxlength , an implicit CHR (0) is added to the end of the STRING, to
allow for variable length during program execution. For this reason a
&H0 may not be used as a portion of a string. Byte arrays can be used
using an allocation as a string, and they may exceed 256 characters. They
may also contain embedded &H0 elements. But if they do, string
operations can not be used. For instance a byte array of &H0, &H1,
&H2 can be built as-
a$(0) = 0
a$(1) =
1
a$(2) = 2
a$(3) = 3
But the following will NOT work-
a$ = chr(0) + chr(1) + chr(2) + chr(3) ' fails as the first 0 terminates this string operation
But it can be done as-
a$ = chr(1) + chr(1) + chr(2) +
chr(3)
a$(0) =
0
' replace the first character with a $0
STRINGs are not checked for length at run time, so care must be taken to
avoid filling it beyond the declared DIM.
Individual characters within a
string can be accessed like an array, such as a$(12) returns the character in
position 13, with the first element at offset 0.
Single character strings are a special case, and usually replaced by the byte constant representing that character. So "A" can be used interchangeably with &H41 or 63.