A
String is an array of characters.
A
String declared without the
size parameter is dynamically resized depending on the length of the string. The length can range from 0 bytes to 2 gigabytes. A descriptor contains a pointer to the actual string and the length of the string.
VarPtr will return a pointer to the descriptor, while
StrPtr will point to the actual string.
Despite the use of the descriptor, an implicit
NULL character (
Chr(0)) is added to the end of the string, to allow passing them to functions in external libraries without making slow copies. FreeBASIC's internal functions will ignore this character, and not treat it as part of the string.
A
String declared with a
fixed size is a QB-style fixed length string, with the exception that unused characters are set to 0, regardless of what "-lang" compiler option is used. It has no descriptor and it is not resized to fit its contents. As in QB, if data overflows the size of the string, it is truncated on the right side.
Fixed length strings are also terminated with a
NULL character, and so they use
size + 1 bytes of space. This
NULL terminator may be removed in future, to prevent the redundant character complicating data layout in user-defined
Types.
String variable names need not end in a dollar sign
$ as in other dialects of BASIC. In
lang fb variable suffixes, including the dollar sign, are disallowed entirely.
Note: When passing
Strings as parameters to
Subs, they should always be passed by reference (
ByRef). Currently,
ByVal does not pass a copy of the string, but a
Pointer to the string data. This can cause unexpected behavior.