Difference between revisions of "LlParseString2List"

From Second Life Wiki
Jump to navigation Jump to search
m
(added some notes)
Line 11: Line 11:
|spec
|spec
|caveats=
|caveats=
*All empty strings (that would arise from a spacer or separator being adjacent to each other or the ends) are removed.
*All empty strings (that would arise from a spacer or separator being adjacent to each other or the ends) are removed;
**If you want them (to keep the order of a list, for example) use [[llParseStringKeepNulls]] instead.
**If you want them (to keep the order of a list, for example) use [[llParseStringKeepNulls]] instead;
* Only the first 8 separators and first 8 spacers will be used any extras will be ignored.
* Only the first 8 separators and first 8 spacers that you specify will be used. Any beyond that will be ignored (see Useful Snippets section below if this is an issue for you);
* All separators and spacers must be strings, all other types will be ignored.
* All separators and spacers must be strings. All other types will be ignored;
* Separators take precedent over spacers. The string is parsed from start to finish, each position is compared against the separators then spacers before moving onto the next position.
* Separators take precedent over spacers. The string is parsed from start to finish. Each position is compared against the separators then spacers before moving onto the next position;
* Duplicate separators and spacers have no ill effects.
* Duplicate separators and spacers have no ill effects;
* All entries in the return are typed as string. Use explicit typecasting on [[llList2String]] to convert the values into other types. Do not rely upon the implicit typecasting of the other llList2* functions (as they typically return a default value).
* All entries in the return are typed as string. Use explicit typecasting on [[llList2String]] to convert the values into other types. Do not rely upon the implicit typecasting of the other llList2* functions (as they typically return a default value);
* Remember to capture the result of the operation with a variable, unless you are planning to act directly on the results.
|constants
|constants
|examples=<lsl>default
|examples=<lsl>default
Line 50: Line 51:
|also_articles={{LSL DefineRow||[[Separate Words]]}}
|also_articles={{LSL DefineRow||[[Separate Words]]}}
{{LSL DefineRow||[[LSL-Editor/Bugs]]}}
{{LSL DefineRow||[[LSL-Editor/Bugs]]}}
|notes
|notes=If instead you indicate that something is a spacer, it will split the string where it finds the space, but leave the spacer there and include it in the results.
 
Example
 
<lsl>
    string myString = "What Are You Looking At?";
 
    llSay(0, (string)llParseString2List(myString, ["W", "A", "Y", "L", "A"], [] ));
    //returns: hat re ou ooking t?
   
    llSay(0, (string)llParseString2List(myString, [], ["W", "A", "Y", "L", "A"] ) );
    //returns: What Are You Looking At?
</lsl>
 
 
Using " " as a separator will parse a sentence into words.
 
If you there is no spacer you care about, just use <code>[]</code> as the spacer.
 
 
|permission
|permission
|negative_index
|negative_index

Revision as of 16:28, 14 July 2008

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 of strings, 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

  • All empty strings (that would arise from a spacer or separator being adjacent to each other or the ends) are removed;
  • Only the first 8 separators and first 8 spacers that you specify will be used. Any beyond that will be ignored (see Useful Snippets section below if this is an issue for you);
  • All separators and spacers must be strings. All other types will be ignored;
  • Separators take precedent over spacers. The string is parsed from start to finish. Each position is compared against the separators then spacers before moving onto the next position;
  • Duplicate separators and spacers have no ill effects;
  • All entries in the return are typed as string. Use explicit typecasting on llList2String to convert the values into other types. Do not rely upon the implicit typecasting of the other llList2* functions (as they typically return a default value);
  • Remember to capture the result of the operation with a variable, unless you are planning to act directly on the results.

Examples

<lsl>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,"><") + ">");
   }
}</lsl>

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.

Appears to be correct at a glance.

Notes

If instead you indicate that something is a spacer, it will split the string where it finds the space, but leave the spacer there and include it in the results.

Example

<lsl>

   string myString = "What Are You Looking At?";
   llSay(0, (string)llParseString2List(myString, ["W", "A", "Y", "L", "A"], [] ));
   //returns: hat re ou ooking t?
   
   llSay(0, (string)llParseString2List(myString, [], ["W", "A", "Y", "L", "A"] ) );
   //returns: What Are You Looking At?

</lsl>


Using " " as a separator will parse a sentence into words.

If you there is no spacer you care about, just use [] as the spacer.

See Also

Functions

•  llParseStringKeepNulls
•  llDumpList2String
•  llCSV2List
•  llList2CSV

Articles

•  Separate Words
•  LSL-Editor/Bugs

Deep Notes

Signature

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