Strings, strings and strings
Posted: Fri Nov 26, 2021 3:47 pm
SharpBASIC supports three types of strings:
Output:
In this example, the fixed length string s0 is copied to s1. The main difference of these two string types lies in the string descriptor, which in SharpBASIC has the format [addr:size].
The size in the descriptor of a variable length string is always null, which tells the compiler that the string pointed to by the address in the descriptor is a null-terminated string. By contrast, the size in the descriptor of a fixed length string is always the actual fixed size of the string.
Constant strings in SharpBASIC do not have a descriptor and are null-terminated.
- variable length, which are null-terminated
- fixed length, which are not null-terminated
- constant strings
Code: Select all
' SharpBASIC stre00
' -------------------
' option strict hint;
incl "lib/sys.sbi";
dim is
s0: str * 24 = "The apple tree is empty.";
s1: str;
s2: str = "Next year is a new round.";
end;
main do
s1 = s0;
print(s1);
s1 = s2;
print(s1);
end;
In this example, the fixed length string s0 is copied to s1. The main difference of these two string types lies in the string descriptor, which in SharpBASIC has the format [addr:size].
The size in the descriptor of a variable length string is always null, which tells the compiler that the string pointed to by the address in the descriptor is a null-terminated string. By contrast, the size in the descriptor of a fixed length string is always the actual fixed size of the string.
Constant strings in SharpBASIC do not have a descriptor and are null-terminated.