# llGetSubString

*LSL function*

```lsl
string string llGetSubString(string src, integer start_index, integer end_index);
```

- `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](https://wiki.secondlife.com/wiki/string) that is the substring of **src** from **start** to **end**, leaving the original [string](https://wiki.secondlife.com/wiki/string) intact.

```lsl title="How to use" frame="terminal"
string result = llGetSubString("", 0, 0);
```

## Examples

<details open>
<summary>Example 1</summary>

```lsl
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
    }
}
```

</details>

<details>
<summary>Example 2</summary>

```lsl collapse={1-18}
// 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);
    }
}
```

</details>

## Notes

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](/functions/llStringLength/).

## See also

### Functions

- [llReplaceSubString](/functions/llReplaceSubString/)
- [llDeleteSubString](/functions/llDeleteSubString/)
- [llInsertString](/functions/llInsertString/)

### Articles

- [CombinedLibrary: str_replace](https://wiki.secondlife.com/wiki/Library_Combined_Library#str-replace)

---

*Source: [LlGetSubString](https://wiki.secondlife.com/wiki/LlGetSubString) on the Second Life Wiki. Content from the Second Life Wiki articles LlGetSubString (revision 1215061, 2023-10-15) and Template:LSL Function/negative index (revision 1200041, 2016-05-02), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llGetSubString/
