llParseString2List

From Second Life Wiki
Revision as of 02:38, 2 October 2007 by Ppaatt Lynagh (talk | contribs) (explicitly state all four preconditions)
Jump to navigation Jump to search

Summary

Function: list llParseString2List( string src, list separators, list spacers );
0.0 Forced Delay
10.0 Energy

Returns a list that is src broken into a list, discarding separators, keeping spacers, discards any null values generated.

• string src source string
• list separators separators to be discarded
• list spacers spacers to be kept

Caveats

  • Never provide more than 8 separators, never provide more than 8 spacers.
  • Provide lists of strings as the separators and spacers, not mixed lists of strings and floats and such.
  • Don't let any spacer contain or equal a separator, and don't let any separator contain or equal a spacer.
  • Do list each spacer and separator only once.
  • Do expect to receive a list of strings in return. Call functions like llList2Integer to get the llGetListEntryType type that you want. Read those caveats too, e.g., cast to integer from llList2String if you want to receive a hexadecimal integer.

Examples

default
{
    state_entry()
    {
        // This will say:
        // <A><crazy><fox><.><Saw><the><moon><.><.>
        string my_string = "A crazy fox.  Saw the moon..";
        list my_list = llParseString2List(my_string,[" "],["."]);
        llOwnerSay("<" + llDumpList2String(my_list,"><") + ">");
        
        // This will say:
        //  <A><crazy><fox><.><><><Saw><the><moon><.><><.><>
        my_list = llParseStringKeepNulls(my_string,[" "],["."]);
        llOwnerSay("<" + llDumpList2String(my_list,"><") + ">");
    }
}

Useful Snippets

Examples of processing more than 8 spacers or separators:

•  ParseString2List Functions exactly the same as llParseString2List and llParseStringKeepNulls.
•  separateWords Functions exactly the same as llParseString2List unless you violate the preconditions.

Also correct at a glance.

Deep Notes

Signature

function list llParseString2List( string src, list separators, list spacers );