2.4. Strings

[<<<] [>>>]

Strings are easily handled in ScriptBasic. A string starts with a " character and stops with another one. For example

A="This is a single line string"
B="Strings may contain \" characters backslash quoted"
C="""Multiline strings should start with three " and
may contain single or double " characters, like "" without backslash"""

Whenever you want to store a string in a variable it is automatically handled. ScriptBasic automatically allocates space to store the string and reuses the memory not needed anymore. You can use single line strings just as well as multi-line strings. Multi-line strings should start and end with three " characters. Strings can contain any character with the code between zero and 255 and can be any length limited by available memory only. In other words ScriptBasic strings are byte-streams or byte strings. You can store arbitrary binary data as string in variables. You can easily type binary data, because any \ character inside a string may be followed by the code of the character. For example you can write

"\32is just a space"

If the first number following the \ character is zero then the code is calculated as octal. There are other characters that can be typed using the \ character. For example:

"\n is a new-lien character"
"\r is a carriage return character"
"\t is a tabulator character"
"\" is a double apostrophe character"
"\\ oh! This is a back-slash character"

Finally there is a very special type of string in ScriptBasic and this is the binary multi-line string. A binary multi-line string should be used to specify binary data that is long and may not fit into a single line if you want to specify it using \000 characters.

To specify a binary multi-line string you have to start your string with the four characters """&. This will instruct the ScriptBasic reader to neglect all new-line characters inside the string unless they are explicitly denoted using \n.

This way you can specify any string and still keep your source code editable with moderated line lengths. For example:

Example string1.bas :

PRINT """&This is a multiline 

string with a single\nnewline in it."""

Result executing string1.bas :

Of course this is not the usual usage of this type of string, but is a more or less readable example.


[<<<] [>>>]