String
string.byte
Shared
Retrieves the internal numeric codes of characters
Syntax
local ... = string.byte(input, start_at = 1, end_at = -1)Parameters
| Type | Name | Description |
|---|---|---|
string | input | String to be converted |
int | start_at | Character position where extraction begins - negative counts from end |
int | end_at | Character position where extraction ends - negative counts from end |
Returns
| Type | Name | Description |
|---|---|---|
... | ... | Numeric byte values for the specified range |
Examples
--Get byte value of first character
local byte = string.byte("A")
engine.print(byte) --65--Get byte value at specific position
local byte = string.byte("ABC", 2)
engine.print(byte) --66--Get multiple byte values
local b1, b2, b3 = string.byte("ABC", 1, 3)
engine.print(b1, b2, b3) --65 66 67--Using negative indices (from end)
local last = string.byte("Hello", -1)
engine.print(last) --111 (character 'o')