Difference between revisions of "LlCSV2List"

From Second Life Wiki
Jump to: navigation, search
Line 6: Line 6:
 
|func_desc
 
|func_desc
 
|return_text=made from '''src''' as comma separated values.
 
|return_text=made from '''src''' as comma separated values.
|spec=Anything between "<" and ">" is considered a single value regardless of the existence of a comma between. For every "<" there needs to be a corresponding ">".
+
|spec=This function takes a string of values separated by commas, and turns it into an LSL list.
 +
 
 +
To do the opposite -- take a list and make it into a comma-separated string -- use [[llList2CSV]].
 +
 
 +
To use separators other than commas (especially if you can't predict when a user might have snuck a comma into data they supply the script), use [[llParseString2List]] instead, which allows you to specify separators other than commas.
 +
 
 +
 
 +
== Rotation and Vector Strings ==
 +
Anything between "<" and ">" is considered a single value regardless of the existence of a comma between.  
 +
 
 +
This ensures that [[vector]]s and [[rotation]]s get treated as a single value, with no additional cleanup needed afterward.
 +
 
 +
Note, though, that for every "<" there needs to be a corresponding ">" :
 +
 
 
<lsl>
 
<lsl>
 
llCSV2List("<>,>,a")  == ["<>", ">", "a"]; //didn't match the last ">"
 
llCSV2List("<>,>,a")  == ["<>", ">", "a"]; //didn't match the last ">"
Line 13: Line 26:
 
</lsl>
 
</lsl>
  
|caveats=*It eats leading and trailing spaces from values.
+
Note as well that Rotations and Vectors included in this list will be strings. You'll need to convert them back to Rotations or Vectors for other use when you haul them out of the list.
* Anything between "<" and ">" is considered a single value, see [[#Specification|Specification]] for further details.
+
 
** This is done so that the function can handle [[vector]]s and [[rotation]]s without extra parsing.
+
 
* All items in the returned list are strings until [[typecast]].
+
== Leading and Trailing Spaces ==
 +
 
 +
llCSV2List eats leading and trailing spaces from values.
 +
 
 +
For example:
 +
 
 +
list tmp = llCSV2List("first , second , third");
 +
 
 +
returns ["first","second","third"]
 +
 
 +
not ["first "," second "," third"]
 +
 
 +
 
 +
== Blank Lists ==
 
* llCSV2List("") returns [""], not []
 
* llCSV2List("") returns [""], not []
 +
 +
 +
 +
|caveats=* As mentioned above under the "Rotation and Vector Strings" section, all items in the returned list (including integers, floats, etc, as well) are strings until [[typecast]] (converted) otherwise by you.
 
|constants
 
|constants
 
|examples=
 
|examples=

Revision as of 18:26, 7 July 2008

Summary

Function: list llCSV2List( string src );

Returns a list made from src as comma separated values.

• string src

Do not confuse this function with the CSV format, it is not the CSV format.

Specification

This function takes a string of values separated by commas, and turns it into an LSL list.

To do the opposite -- take a list and make it into a comma-separated string -- use llList2CSV.

To use separators other than commas (especially if you can't predict when a user might have snuck a comma into data they supply the script), use llParseString2List instead, which allows you to specify separators other than commas.


Rotation and Vector Strings

Anything between "<" and ">" is considered a single value regardless of the existence of a comma between.

This ensures that vectors and rotations get treated as a single value, with no additional cleanup needed afterward.

Note, though, that for every "<" there needs to be a corresponding ">" :

<lsl> llCSV2List("<>,>,a") == ["<>", ">", "a"]; //didn't match the last ">" llCSV2List("<<>,>,a") == ["<<>,>", "a"]; //matched everything llCSV2List("<<<>,>,a") == ["<<<>,>,a"]; //didn't match the last "<" </lsl>

Note as well that Rotations and Vectors included in this list will be strings. You'll need to convert them back to Rotations or Vectors for other use when you haul them out of the list.


Leading and Trailing Spaces

llCSV2List eats leading and trailing spaces from values.

For example:

list tmp = llCSV2List("first , second , third");

returns ["first","second","third"]

not ["first "," second "," third"]


Blank Lists

  • llCSV2List("") returns [""], not []

Caveats

  • As mentioned above under the "Rotation and Vector Strings" section, all items in the returned list (including integers, floats, etc, as well) are strings until typecast (converted) otherwise by you.
All Issues ~ Search JIRA for related Bugs

Examples

<lsl> default {

   state_entry()
   {
       string csv = "first,second,third";
       list my_list = llCSV2List(csv);
       llOwnerSay("CSV: " + csv);
       integer i;
       for (i=0; i<llGetListLength(my_list); ++i)
       {
           llOwnerSay("my_list[" + (string)i + "]: " + llList2String(my_list,i));
       }
   }
}</lsl>

See Also

Functions

•  llList2CSV
•  llDumpList2String
•  llParseString2List
•  llParseStringKeepNulls

Articles

•  Typecast

Deep Notes

Search JIRA for related Issues

Signature

function list llCSV2List( string src );