# llOrd

*LSL function*

```lsl
integer integer llOrd(string val, integer index);
```

- `string val`: Source string.
- `integer index`: Codepoint index of the character to convert. Supports negative indexing.

- Returns: `integer`
- Energy: 10

Calculate the ordinal value for a character in a string.

The returned value is the UTF-32 value of the character at the specified index. If index is outside the bounds of the string, this function returns 0.

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

## Caveats

- Characters in the surrogate range (`"\u{D800}"` - `"\u{0xDFFF}"`) will return `0x3F` = `63`. This might not be observable on LSL, only SLua. SLua's equivalent `utf8.codepoint` instead raises an error `"invalid UTF-8 code"` in this situation.

## Examples

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

```lsl collapse={1-10, 16-28}
default
{
    touch_start(integer total_number)
    {
        string test_string = "The quick brown fox jumped over the lazy dog";
        list test_list = [];
        string test_string2 = "";

        integer index;
        integer ord;
        for (index = 0; index < llStringLength(test_string); ++index)
        {
            ord = llOrd(test_string, index);
            test_list = test_list + [ ord ];
        }

        string char;
        for (index = 0; index < llGetListLength(test_list); ++index)
        {
            ord = llList2Integer(test_list, index);
            char = llChar(ord);
            test_string2 = test_string2 + char;
        }

        llSay(0, "\"" + test_string + "\" -> [" +
            llDumpList2String(test_list, ", ") + "] -> \"" + test_string2 + "\"");
    }
}
```

</details>

## See also

### Functions

- [llChar](/functions/llChar/) — Convert an ordinal into a character
- [llHash](/functions/llHash/) — Calculate a 32bit hash for a string

### Articles

- [UTF-32](https://en.wikipedia.org/wiki/UTF-32)

---

*Source: [LlOrd](https://wiki.secondlife.com/wiki/LlOrd) on the Second Life Wiki. Content from the Second Life Wiki articles LlOrd (revision 1218695, 2026-03-13) and Template:LSL Function/negative index (revision 1200041, 2016-05-02), CC BY-SA 3.0.*

---

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