llGetSubString
string llGetSubString(string src,// Source string to slice.integer start_index,// Starting codepoint index (inclusive). Supports negative indexing.integer end_index// Ending codepoint index (inclusive). Supports negative indexing.
);- Returns
string- Energy
- 10
Returns a copy of the substring from src within the inclusive codepoint range start_index..end_index. Negative indices count backward from the end of the string. If start_index is greater than end_index, the substring is the excluded range.
Returns a string that is the substring of src from start to end, leaving the original string intact.
string result = llGetSubString("", 0, 0);Examples
Section titled “Examples”Example 1
default{ state_entry() { string word = "Hello!"; llOwnerSay(llGetSubString(word, 0, 0)); // Object: H llOwnerSay(llGetSubString(word, -1, -1)); // Object: ! llOwnerSay(llGetSubString(word, 2, 3)); // Object: ll }}Example 2
18 collapsed lines
// display SL time using a script without an 'if'default{ state_entry() { // synchronise our clock to a fraction of a second float fnow = llGetWallclock(); while (fnow == llGetWallclock() ) ; // await a change in seconds
llSetTimerEvent(1.0); }
timer() { integer seconds = (integer) llGetWallclock(); integer minutes = seconds / 60; seconds = seconds % 60; integer hours = minutes / 60; minutes = minutes % 60;
string stringHours = llGetSubString("0" + (string)hours, -2, -1); string stringMinutes = llGetSubString("0" + (string)minutes, -2, -1); string stringSeconds = llGetSubString("0" + (string)seconds, -2, -1);
string time = stringHours + ":" + stringMinutes + ":" + stringSeconds;
llSetText(time, <1.0, 1.0, 1.0>, 1.0); }}The counting of the characters starts at 0. Using 0,0 as start and end positions would return the first character only. Using negative numbers causes backwards counting, so -1 is shortform for the last character in a string. Ergo, using 0, -1 as start and end positions would return the entire string.
To ascertain how long a string is, use llStringLength.
See also
Section titled “See also”Functions
Section titled “Functions”Articles
Section titled “Articles”Original wiki source
Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.