Language basics / Data types |
The STRING data type is a variable-length, dynamically allocated character string data type, without limitation.
STRING
The STRING data type is typically used to implement utility functions manipulating character string with unknown size, and in some special cases, in SQL statements.
STRING variables are initialized to NULL in functions, modules and globals.
The behavior of a STRING variable is similar to the VARCHAR data type, except that there is no theoretical size limit.
MAIN DEFINE s STRING LET s = "abcdef" END MAIN
MAIN DEFINE s STRING LET s = "abc" DISPLAY s.toUpperCase() END MAIN
MAIN DEFINE s STRING LET s = "abc " -- a b c + 2 white spaces DISPLAY "1: s.length:", s.getLength() DISPLAY "[", s, "]" -- displays "[abc ]" DISPLAY IIF(s=="abc","Equals",NULL) END MAIN
MAIN DEFINE s STRING LET s = " " -- 5 spaces LET s = s.trim() DISPLAY "s = [", s, "] len=", s.getLength() DISPLAY IIF(s IS NULL, "NULL", "not NULL") END MAIN outputs: s = [] len= 0 not NULL
STRING typed variables can be used in some special cases to hold SQL character string data, when the size of the SQL data string is not known (string expressions, large strings like JSON documents). In order to store character string data stored in a database, consider using the CHAR or VARCHAR types instead of STRING.
In STRING methods, positions and length parameters (or return values) can be expressed in bytes or characters, depending on the length semantics used in programs. For more details, see Length semantics settings