Difference between revisions of "Category:LSL Negative Index"
Jump to navigation
Jump to search
Kelly Linden (talk | contribs) |
m |
||
Line 1: | Line 1: | ||
Negative indexes | Negative indexes count backwards from the end. | ||
For ''string s = "Hello World"'' | For ''string s = "Hello World"'' | ||
* Index 0 is 'H' (''llGetSubString(s,0,0)'') | * Index 0 is 'H' (''llGetSubString(s,0,0)'') | ||
Line 6: | Line 7: | ||
Care must be taken when using the results of | Care must be taken when using the results of [[llListFindList]] and [[llSubStringIndex]] in combination with the functions in this category. Those functions will return an index of -1 to indicate 'not found', which if used in these functions is a valid index - but probably not the one you want. | ||
<pre> | |||
string s = "Hello World"; | |||
integer index = llSubstringIndex(s, "t");//index == -1 | |||
if(~index)//same as doing (index != -1) but a bit faster, '~' inverts the bits (-1 == all on) so (~-1 == all off) | |||
{ | |||
s = llDeleteSubString(s, index, index); | |||
} | |||
</pre> |
Revision as of 15:01, 6 March 2007
Negative indexes count backwards from the end.
For string s = "Hello World"
- Index 0 is 'H' (llGetSubString(s,0,0))
- Index -1 is 'd' (llGetSubString(s,-1,-1))
- Index -5 is 'W' (llGetSubString(s,-5,-5))
Care must be taken when using the results of llListFindList and llSubStringIndex in combination with the functions in this category. Those functions will return an index of -1 to indicate 'not found', which if used in these functions is a valid index - but probably not the one you want.
string s = "Hello World"; integer index = llSubstringIndex(s, "t");//index == -1 if(~index)//same as doing (index != -1) but a bit faster, '~' inverts the bits (-1 == all on) so (~-1 == all off) { s = llDeleteSubString(s, index, index); }
Pages in category "LSL Negative Index"
The following 18 pages are in this category, out of 18 total.