Difference between revisions of "LlParseString2List"

From Second Life Wiki
Jump to navigation Jump to search
m (add Separate Words to the list of helpers - although that markup looks wrong to me, these are not LSL functions, these are Script Library)
Line 32: Line 32:
     }
     }
}</pre>
}</pre>
|helpers={{LSL Functions/ParseString2List}}
|helpers=
{{LSL Functions/Separate_Words}}
'''Replacement functions without or very large separator/spacer count limits'''
{{{!}}
{{LSL DefineRow||[[ParseString2List]]|Functions exactly the same as [[llParseString2List]] and [[llParseStringKeepNulls]]}}
{{LSL DefineRow||[[Separate Words|separateWords]]|Functions the same as [[llParseString2List]] except in specific instances of overlaps between spacers and separators}}
{{!}}}
|also_functions=*{{LSLG|llParseStringKeepNulls}}
|also_functions=*{{LSLG|llParseStringKeepNulls}}
*{{LSLG|llDumpList2String}}
*{{LSLG|llDumpList2String}}

Revision as of 21:41, 27 September 2007

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

separators and spacers must be lists of strings, maximum of 8 each.

Caveats

  • To avoid contradiction, every string of the spacers list of strings to keep must not exist in the separators list of strings to discard.
  • Every element in the list will be a string, no matter what you think it should be. Cast the results of llList2String to get what you want.
    • integer my_int = (integer)llList2String(my_list, i);
  • llList2String is used here, as llList2Integer can only handle integers in simple notation, ie. will not handle hexadecimal integers.

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

Replacement functions without or very large separator/spacer count limits

•  ParseString2List Functions exactly the same as llParseString2List and llParseStringKeepNulls
•  separateWords Functions the same as llParseString2List except in specific instances of overlaps between spacers and separators

Deep Notes

Signature

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