String
DIM Var AS String
This datatype represents a variable-length string of characters.
An ASCII string can be easily accessed as an array of characters (strings with a length of one). Array indexes start at zero, so the first character in a string would be at index zero. This is not the case when strings are used in functions. Also, be sure to use the
UTF-8 String Functions when working with UTF-8 strings.
When used in
String Functions, the first character of a string is numbered one, not zero.
Theoretically, the string can contain null characters (i.e. character whose ASCII code is zero). But as some Gambas functions internally rely on zero-terminated strings, especially the methods of native class having string arguments, you should avoid them as much as possible!
String escape characters
A string constant can contain the following escape characters:
Escape character
|
ASCII equivalent
|
\n
|
Chr$(13)
|
\r
|
Chr$(10)
|
\t
|
Chr$(9)
|
\b
|
Chr$(8)
|
\v
|
Chr$(11)
|
\f
|
Chr$(12)
|
\e
|
Chr$(27)
|
\0
|
Chr$(0)
|
\"
|
Double quote
|
\\
|
Backslash
|
\xNN
|
Chr$(&HNN)
|
Examples
PUBLIC sPub AS String ' This string can be used by all subroutines in the same module
PUBLIC SUB Button1_Click()
DIM sLoc AS String ' This string is local in this subroutine
sPub = "74zu88"
sLoc = Mid$(sPub, 3, 2)
IF sLoc = "zu" THEN PRINT "Expected"
END
' For convenience and readability, exceptionally long strings can be defined on multiple lines.
Dim MyString As String = ""
"Pretend "
"this "
"is "
"a "
"really "
"long "
"string."
Print MyString ' Prints: Pretend this is a really long string.
Pretend this is a really long string.
See also