Difference between revisions of "LlList2String"

From Second Life Wiki
Jump to navigation Jump to search
m
m (<lsl> tag to <source>)
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{LSL_Function/list/element|src|index|string|return={{HoverText|null string|null string: ""}}}}{{LSL_Function
{{LSL_Function
|inject-2={{LSL_Function/list/element|src|index|string|nf=*|return={{HoverText|null string|null string: ""}}}}
|func_id=188|func_sleep=0.0|func_energy=10.0
|func_id=188|func_sleep=0.0|func_energy=10.0
|func=llList2String|return_type=string|p1_type=list|p1_name=src|p2_type=integer|p2_name=index
|func=llList2String|return_type=string|p1_type=list|p1_name=src|p2_type=integer|p2_name=index
|func_footnote
|func_footnote
|func_desc
|func_desc
|return_text=that is at '''index''' in '''src'''.
|return_text=that is at {{LSLP|index}} in {{LSLP|src}}.
|spec
|spec
|caveats=*When using this function to typecast a list element to a string it will truncated float types to 6 decimal places.
|caveats=*When using this function to typecast a list element to a string it will truncated float based types to 6 decimal places.
|constants
|constants
|examples=<lsl>//This code demonstrates the differences in typecasting in LSL (and demonstrates how to use the llList2* functions).
|examples=<source lang="lsl2">//This code demonstrates the differences in typecasting in LSL (and demonstrates how to use the llList2* functions).
// Best viewed in Chat History (ctrl-h)
// Best viewed in Chat History (ctrl-h)
default
default
Line 27: Line 28:
         }
         }
     }
     }
}</lsl>
}</source>
|helpers
|helpers
|also_functions={{LSL DefineRow||[[llGetListEntryType]]|}}
|also_functions={{LSL DefineRow||[[llDumpList2String]]|}}
{{LSL DefineRow||[[llGetListEntryType]]|}}
{{LSL DefineRow||[[llList2Float]]|}}
{{LSL DefineRow||[[llList2Float]]|}}
{{LSL DefineRow||[[llList2Integer]]|}}
{{LSL DefineRow||[[llList2Integer]]|}}
Line 36: Line 38:
|also_tests
|also_tests
|also_articles
|also_articles
|notes=
|notes=*If you wish to extract a string from a list that you know will contain only a single item (for example if you extract a single entry from a list using [[llList2List|llList2List()]]), then instead of using <code>llList2String(myList, 0)</code> you may wish to considering using the more efficient <code>(string)myList</code> as it will produce the same result for single-entry lists with less memory usage due to eliminating a function-call.
To convert a string of hex nybbles to integer, call [[llList2String]] and then type cast that string result to integer.
*To convert a string of hexadecimal notation to integer, call [[llList2Integer]] and it will automatically cast the value as decimal integer. To convert that integer back to a string of hexadecimal notation, use a user function like [[hex]].
 
To convert that integer back to a string of hex nybbles, call [[hex]].
|permission
|permission
|cat1=List
|cat1=List

Latest revision as of 11:47, 22 January 2015

Summary

Function: string llList2String( list src, integer index );

Returns a string that is at index in src.

• list src List containing the element of interest.
• integer index Index of the element of interest.

index supports negative indexes.
If index describes a location not in src then null string is returned.
If the type of the element at index in src is not a string it is typecast to a string.

Specification

Index Positive Negative
First 0 -length
Last length - 1 -1

Indexes

  • Positive indexes count from the beginning, the first item being indexed as 0, the last as (length - 1).
  • Negative indexes count from the far end, the first item being indexed as -length, the last as -1.

Caveats

  • If index is out of bounds the script continues to execute without an error message.
  • When using this function to typecast a list element to a string it will truncated float based types to 6 decimal places.
All Issues ~ Search JIRA for related Bugs

Examples

//This code demonstrates the differences in typecasting in LSL (and demonstrates how to use the llList2* functions).
// Best viewed in Chat History (ctrl-h)
default
{
    state_entry()
    {
        list my_list = ["a", "0xFF", "0xFF.FF", "1.0e3", 1, 2.0, <1,2,3>, <1,2,3,4>, llGetOwner()];
        integer i = 0;
        integer end = llGetListLength(my_list);
        for (; i<end; ++i)
        {
            llOwnerSay("string=" + llList2String(my_list,i)
                        + "\n   integer=" + (string)llList2Integer(my_list,i) + " OR " +(string)((integer)llList2String(my_list,i))
                        + "\n   float=" + (string)llList2Float(my_list,i) + " OR " +(string)((float)llList2String(my_list,i))
                        + "\n   vector=" + (string)llList2Vector(my_list,i) + " OR " +(string)((vector)llList2String(my_list,i))
                        + "\n   rot=" + (string)llList2Rot(my_list,i) + " OR " +(string)((rotation)llList2String(my_list,i))
                        + "\n   key=" + (string)llList2Key(my_list,i) + " OR " +(string)((key)llList2String(my_list,i)) );
        }
    }
}

Notes

  • If you wish to extract a string from a list that you know will contain only a single item (for example if you extract a single entry from a list using llList2List()), then instead of using llList2String(myList, 0) you may wish to considering using the more efficient (string)myList as it will produce the same result for single-entry lists with less memory usage due to eliminating a function-call.
  • To convert a string of hexadecimal notation to integer, call llList2Integer and it will automatically cast the value as decimal integer. To convert that integer back to a string of hexadecimal notation, use a user function like hex.

See Also

Functions

•  llDumpList2String
•  llGetListEntryType
•  llList2Float
•  llList2Integer
•  llList2Key

Articles

•  Negative Index

Deep Notes

Search JIRA for related Issues

Signature

function string llList2String( list src, integer index );