Unofficial LSL Reference

[[types:string]]


Unofficial LSL reference

User Tools

Login

You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.

Login

Forgotten your password? Get a new one: Set new password

This is an old revision of the document!


The string type represents a sequence of characters. Character support varies between LSO and Mono: LSO supports any byte sequence that does not contain NUL, even though some of them are not representable in Unicode, while Mono only supports valid Unicode sequences (also not containing NUL).

A string literal is written by enclosing it in double quotes. It may be empty, and does not need to end at the end of the line, but if there are newlines embedded in the literal, they will be part of it. Here are some examples:

""

"This is a string literal"

"☑ Check!"

"A line
and another line"

These four examples are string literals representing the empty string, the string This is a string literal, the string ☑ Check! and the string A line followed by a newline character and by and another line.

Inside the double quotes, there are two special characters: the double quote itself ", which obviously closes the string, and the backslash character \. The double quote closes the string literal, unless preceded by a backslash. The backslash is used as a prefix for any character that is to be interpreted literally, including the backslash itself and the double quote. The exceptions are if the backslash is followed by a lower case n or t. A backslash followed by a n is interpreted as a newline, and a backslash followed by a t is interpreted as four spaces. Examples:

"Press \"OK\" to confirm"

"\tThis is indented by 4 spaces"

"\\o/\n|\n/ \\"

"a\nb"

"a
b"

The first string literal represents the string Press "OK" to confirm; the second string literal represents a string that has four spaces followed by This is intdented by 4 spaces, and the third one represents the string \o/ followed by a newline, then a |, another newline, and then a the string / \, which in hovering text may look like this:

\o/
 |
/ \

The last two examples represent the same string, namely the letter a followed by a newline and the letter b.

Note that indentation spaces will become part of the string if used inside a string literal, for example:

default
{
    state_entry()
    {
        llOwnerSay("String split.
                    Indented part.");
    }
}

will represent the string literal String split. followed by a newline, then twenty spaces, then Indented part.

Finally, string literals may be immediately preceded by the upper case letter L (with no spaces in between). The intention seemed to be to ignore it, but due to a bug in the compiler, it has a funny side effect: the first double quote character is taken as part of the string. For example, the string literal L"String literal" actually represents the string "String literal.

The string type is universal in the sense that it may be cast to and from any other type:

  • (string)integer_value converts it to decimal. See Type casting an integer to/from other types for details.
  • (string)float_value converts it to decimal with six significant digits. See Precision for details.
  • (string)key_value converts a key to string. The key type acts like a string (though it is intended for other uses), therefore the conversion is literal.
  • (string)vector_value converts the vector to a string with three comma-separated floats enclosed in angle brackets, but with five decimal places instead of six. See Precision for details.
  • (string)rotation_value does the same but with the four values of the rotation instead of three.
  • (string)list_value converts the list by casting every element to string and then concatenating them all together. That is, it does the same as llDumpList2String(list_var, "").In this case, however, vectors and rotations are converted with six decimal places per float.
  • (integer)string_value tries to parse the string as an integer. See Type casting an integer to/from other types for details. If the parsing fails, 0 is the result instead.
  • (float)string_value tries to parse the string as a float. The expected format is that from the glibc function strtod. See glibc: Parsing of Floats for details. Hexadecimal floats, as specified there, are supported. If the parsing fails, 0.0 is the result instead.
  • (key)string_value converts the string to key. The resulting value may not be a valid UUID, but the key type is still able to hold any string, so the conversion is lossless.
  • (vector)string_value tries to parse the string as a vector. It expects a < followed by three comma-separated floats (see above for the format of the expected float). If the parsing fails, ZERO_VECTOR is the result instead.
  • (rotation)string_value is similar to vector.
  • (list)string_value returns a list with one single element of type string.