Don't click here unless you want to be banned.

LSL Wiki : llGetSubString

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org
string llGetSubString(string source, integer start, integer end)

Returns a copy of source containing the indicated substring. source is unaltered.

The start and end are inclusive, so 0, length - 1 would capture the entire string and 0, 0 would capture the first character. Using negative numbers for start and/or end causes the index to count backwards from the length of the string, so 0, -1 would capture the entire string. If start is larger than end the substring is the exclusion of the entries, so 6,4 would give the entire string except for the 5th character. If you wish to return the last character in a string, use -1, -1 , the last two, use -2, -1 , etc.

This behavior is similar but opposite to that of the llDeleteSubString function.

To determine the length of a string, use llStringLength.

Example:
string result = llGetSubString("abcd", 0, -1); // gets "abcd"
string result = llGetSubString("abcd", 1, -2); // gets "bc"
string result = llGetSubString("abcd", 1, 3); // gets "bcd"
string result = llGetSubString("abcd", -2, -1); // gets "cd"
string result = llGetSubString("abcd", 0, 2); // gets "abc"


This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions | String
Comments [Hide comments/form]
llGetSubString("Hello, world!",14,15) returns nothing, as it should, because there's no 14th character. However, llGetSubString("Hello, world!",14,-1) returns the entire string. Is this the expected behavior?
-- BobBauhaus (2005-01-24 19:16:49)
Yes, it is. The -1 is effectivly 12 (the index of the last character of the string), so you're saying llGetSubString("Hello, world!", 14, 12). Since the end is lower then the start it excludes the characters between them, which in this case is nothing, and so it returns the whole string.
-- NoeticEidolon (2005-03-10 00:23:35)
This exclusion feature makes it difficult to extract everything after the end of a string, which occurs if you are matching a substring that happens to end at the end of string. Workaround: add something to the end of your string, and remove it again later.
-- ZenoConcord (2005-07-23 20:59:04)
Nope, not wrong... They both will return "bc".

0 = a, 1 = b, 2 = c, 3 = d
-1 = d, -2 = c, -3 = b, , -4 = a

llGetSubString("abcd", 1, -2)
1 = b and -2 = c

llGetSubString("abcd", 1, 2);
1 = b and 2 = c
-- CoryFimicoloud (2007-07-24 10:54:39)
Attach a comment to this page: