Don't click here unless you want to be banned.

LSL Wiki : string

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ec2-204-236-235-245.compute-1.amazonaws.com

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.

Function Name Purpose
llDeleteSubString Removes a slice of a string
llDumpList2String Turns a list into a string
llParseString2List
llParseStringKeepNulls
Turns a string into a list
llGetSubString Extracts a part of a string
llInsertString Inserts a string into a string
llToLower Converts a string to lowercase
llToUpper Converts a string to UPPERCASE
llStringLength Gets the length of a string
llStringTrim Trims leading and/or trailing spaces from a string
llSubStringIndex Finds the position of a string in another string
llEscapeURL Returns the string that is the URL-escaped version of url (replacing spaces with %20, etc)
llUnescapeURL Returns the string that is the URL unescaped version of url, replacing "%20" with spaces, etc.


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
There are 9 comments on this page. [Display comments/form]