Difference between revisions of "LlDumpList2String"

From Second Life Wiki
Jump to navigation Jump to search
m (Quick note that when typecasting list as string, each list item is converted to a string value (so floats/vectors/etc might "gain" unexpected digits of precision))
 
(5 intermediate revisions by 4 users not shown)
Line 4: Line 4:
|func_footnote=Use [[llParseString2List]] or [[llParseStringKeepNulls]] to undo the process.
|func_footnote=Use [[llParseString2List]] or [[llParseStringKeepNulls]] to undo the process.


Unlike [[llList2CSV]] , which dumps a list to a comma-separated formatted string with no choice over the separator, llDumpList2String gives you more control. This can be useful if you don't trust commas as a separator because you might be working with data supplied to the script by a user who uses, say, commas as part of a street address.
Unlike [[llList2CSV]], which dumps a list to a comma-separated formatted string with no choice over the {{LSLPT|separator}}, llDumpList2String gives you more control. This can be useful if you don't trust commas as a {{LSLPT|separator}} because you might be working with data supplied to the script by a user who uses, say, commas as part of a street address.
|func_desc
|func_desc
|return_text=that is the list '''src''' converted to a string with '''separator''' between the entries.
|return_text=that is the list {{LSLPT|src}} converted to a string with {{LSLPT|separator}} between the entries.
|spec
|spec
|notes
|notes
Line 12: Line 12:
|constants
|constants
|examples=
|examples=
<lsl>list mylist = ["a", "b", "c", "d"];
<source lang="lsl2">list mylist = ["a", "b", "c", "d"];
string tmp = llDumpList2String(mylist, " ** ");
string tmp = llDumpList2String(mylist, "**");
//tmp now equals: "a**b**c**d"</lsl>
//tmp now equals: "a**b**c**d"</source>


<lsl>list mylist = [<10,5,7>, 100, "c", "d"];
<source lang="lsl2">list mylist = [<10,5,7>, 100, "c", "d"];
string tmp = llDumpList2String(mylist, "**");
string tmp = llDumpList2String(mylist, "**");
//tmp now equals: "<10,5,7>**100**c**d"</lsl>
//tmp now equals: "<10,5,7>**100**c**d"</source>


<lsl>default{
<source lang="lsl2">default{
     state_entry(){
     state_entry(){
         list my_list = [1, 2.0, "a string", llGetOwner()];
         list my_list = [1, 2.0, "a string", llGetOwner()];
         llOwnerSay("<" + llDumpList2String(my_list,"><") + ">");         
         llOwnerSay("<" + llDumpList2String(my_list,"><") + ">");  
//says: "<1><2.000000><a string><a822ff2b-ff02-461d-b45d-dcd10a2de0c2>"        
     }
     }
}</lsl>
}</source>
|helpers
|helpers
|also_functions=*{{LSLG|llParseString2List}}
|also_functions=*{{LSLG|llParseString2List}}
Line 34: Line 35:
|also_tests
|also_tests
|also_articles=*{{LSLG|Typecast}}
|also_articles=*{{LSLG|Typecast}}
|notes=Instead of using <lsl>llDumpList2String(myList, "")</lsl> you should use <lsl>(string)myList</lsl>
|notes=Instead of using <code>llDumpList2String(myList, "")</code> you may wish to consider using the more efficient <code>(string)myList</code> as it produces an identical result with less memory usage due to eliminating a function-call. Each element of the list is converted to string format in the result, so floats expand to six digits of precision, rotations and vectors are represented with "<" and ">" characters, etc.
|permission
|permission
|negative_index
|negative_index

Latest revision as of 16:49, 5 July 2017

Summary

Function: string llDumpList2String( list src, string separator );

Returns a string that is the list src converted to a string with separator between the entries.

• list src
• string separator

Use llParseString2List or llParseStringKeepNulls to undo the process.

Unlike llList2CSV, which dumps a list to a comma-separated formatted string with no choice over the separator, llDumpList2String gives you more control. This can be useful if you don't trust commas as a separator because you might be working with data supplied to the script by a user who uses, say, commas as part of a street address.

Examples

list mylist = ["a", "b", "c", "d"];
string tmp = llDumpList2String(mylist, "**");
//tmp now equals: "a**b**c**d"
list mylist = [<10,5,7>, 100, "c", "d"];
string tmp = llDumpList2String(mylist, "**");
//tmp now equals: "<10,5,7>**100**c**d"
default{
    state_entry(){
        list my_list = [1, 2.0, "a string", llGetOwner()];
        llOwnerSay("<" + llDumpList2String(my_list,"><") + ">"); 
//says: "<1><2.000000><a string><a822ff2b-ff02-461d-b45d-dcd10a2de0c2>"        
    }
}

Notes

Instead of using llDumpList2String(myList, "") you may wish to consider using the more efficient (string)myList as it produces an identical result with less memory usage due to eliminating a function-call. Each element of the list is converted to string format in the result, so floats expand to six digits of precision, rotations and vectors are represented with "<" and ">" characters, etc.

Deep Notes

Search JIRA for related Issues

Signature

function string llDumpList2String( list src, string separator );