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

LSL Wiki : string

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org

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
Comments [Hide comments/form]
What about llParseStringKeepNulls()?
-- ResunaOddfellow (2005-11-01 13:39:41)
Added. Thanks for pointing that out :-)
-- ChristopherOmega (2005-11-22 19:52:53)
I added llEscapeURL and llUnescapeURL because in my opinion those functions manipulate a string, and also they don't seem to be linked from anywhere except the main functions page. I had a bit of trouble finding them. Maybe they should be mentioned on the Communications page too?
-- KermittQuirk (2006-06-03 00:50:24)
I found integers cannot be concatenated if you use "string + (string)integer". You must turn the integer to a string first "string2 = (string)integer", then add 2 strings. Otherwise you get a Syntax Error.
-- LasivianLeandros (2006-08-20 12:14:20)
Lasivian you are incorrect.

Try
default
{
    state_entry()
    {
        integer a = 39;
        string b = "hello ";
        string c = b + (string)a;
        string d = "bye "+ (string)a;
        string e = "word"+(string)5;
    }
}
-- BlindWanderer (2006-08-20 18:28:46)
How do I compare one string less than another?

Try1: Iterate through the string
- character type dose not exist so there is nothing to iterate
Try2: use integer <
- Directly casting to integer always becomes 0
- Using llStringToBase64() then llBase64ToInteger() also becomes 0
Try3: use list functions
This solution works but is unacceptably slow
- add both strings to an empty list, sort the list, search for the first string, if index is 0 return TRUE
-- DustinTrilling (2006-11-02 07:26:06)
what is the upper bound of an array or string?
like if I am storing names in a string , what is the maximum no of names I can store?
-- 125.18.104.1 (2007-09-14 04:39:29)
I'm also befuddled by the notion that there aren't any built-in string comparisons. This makes absolutely no sense.

I'm just trying to compare two dates, and llGetDate hands me a string.
-- c-67-183-18-191.hsd1.wa.comcast.net (2007-10-24 15:34:58)
"Using llStringToBase64() then llBase64ToInteger() also becomes 0"

Works for me, assuming you make sure it doesn't overflow.
-- 68-187-144-197.dhcp.stcd.mn.charter.com (2007-11-27 12:55:16)
Attach a comment to this page: