String
Atap Fiberglass &
Tangki Fiberglass
A
string is a sequence of
characters limited in length only by available
memory. Strings are enclosed in quotation marks (").
LSL uses
UTF-8 for its encoding standard for strings.
Example:
string foo = "bar"; // this defines a string named "foo", containing the text "bar"
Strings can be
concatenated using the plus sign (
+)
operator.
The
hack to increase max stored
list size works for strings as well:
myString = (myString="") + myString + "new_item";
Example:
// This adds the text "anotherstring"
// and the result of (string)PI_BY_TWO to the end of an existing string.
mystring = yourstring + "anotherstring" + (string)PI_BY_TWO;
(In this example, the text "
(string)PI_BY_TWO" converts the
float constant PI_BY_TWO to a string. This process is called
typecasting.)
Escape Characters
In
LSL, strings can contain some backslash (\) escape characters:
Substring | Replaced with |
\t | four spaces |
\n | new line |
\" | double quote |
\\ | backslash |
These are just a subset of the backslash escape characters found in any other language. If a backslash is used in a string, and it is not paired up with one of the above characters and it will be treated as "\\". These escape characters only work in
compiled
scripts. In other words, a
listener cannot be used to find the "new line" escape sequence and then treat it as the
compiler would. However, a predefined string containing "\n" can be substituted for an input escape character sequence.
Functions
These
functions are only a few of the many that
use strings, but they're the ones that
manipulate strings.
LSL doesn't appear to have any direct way to compare two strings for alphabetical order; here's a hack.
integer CompareStrings(string a,string b) {
//returns -1 if they are in alphabetical order
//1 if in reverse alphabetical order
//0 if equal
if(a==b){return 0;}
if(a==llList2String(llListSort([a,b],1,TRUE),0)) {return -1;} else {return 1;}
}
Functions |
Types |
Memory Usages