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

LSL Wiki : llParseString2List

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are
list llParseString2List(string src, list separators, list spacers)

Breaks src into a list, splitting at and discarding separators, and splitting at and keeping spacers (separators and spacers must be lists of strings, maximum of 8 each). All instances of each separator will be used to parse the string. Empty strings are not returned by this function - if you need those, look at llParseStringKeepNulls. If none of separators are found in the src returns a list of a single element containing the whole src (do not forget that the index of this element is 0). This means you can use this function to search for separators in src. This is much faster than using llSubStringIndex (0.065s compared to 0.157s).

llParseString2List("one,two,three,'four','five,six' ",[","],[]);

Will produce the list:
["one", "two", "three", "'four'", "'five", "six' "]

llParseString2List("one,two,three,'four','five,six' ",[",","'"],[]);

Will produce the list:
["one", "two", "three", "four", "five", "six", " "]

llParseString2List("A:B::D", [":"], []);

Will get the list:
["A", "B", "D"]

llParseString2List("AllCowsEatGrass", ["A", "C", "E", "G"], []);

Will get the list:
["ll", "ows", "at", "rass"]

llParseString2List("AllCowsEatGrass", [], ["A", "C", "E", "G"]);

Will get the list:
["A", "ll", "C", "ows", "E", "at", "G", "rass"]

So, when ["A", "C", "E", "G"] was in separators, it removed them, then split the string at that point. When ["A", "C", "E", "G"] was in spacers, it splits the string before and after each spacer, leaving the spacer intact.

To split a sentence into words by using " " as the separator:
llParseString2List("All Cows Eat Grass", [" "], []);

Returns this list:
["All", "Cows", "Eat", "Grass"]

Useful function to retrieve a first name from an avatar's entire name (excluding group).
string getFirstName(string fullName) 
     return llList2String(llParseString2List(fullName,[" "],[]),0);

Be very careful about using this function on strings that may have been input from untrusted sources (for example, strings heard in open chat via a listen() event). A list with a large number of items can consume a large amount of a script's memory, potentially causing it to halt with a stack/heap collision error; disruptive users may try to crash your script by deliberately speaking strings that will parse to extremely large lists.

Question: Is there a way to separate letters without a spacer? Such as: list test = llParseString2List("foobar", [???], [""]); Returns: test == ["f", "o", "o", "b", "a", "r"]
Answer: The only way I know of doing so is by taking the string apart piece by piece using a loop:
integer i; //counter
integer stringLength = llStringLength(src);
list seperatedString = [];

for (i = 0; i < stringLength; ++i)
seperatedString += [llGetSubString(src, i, i)];
- CarigorpMatzerath

llParseStringKeepNulls: keeps null strings between separators or spacers
llDumpList2String: performs the opposite function.

See also llCSV2List and ExampleListConversion.

This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions | Lists | Strings
There are 2 comments on this page. [Display comments/form]