util.string.byte

Shared

Retrieves the internal numeric codes of characters


Syntax

local ... = util.string.byte(
    input,
    start_at = 1,
    end_at = -1
)

Parameters

TypeNameDescription
stringinputString to convert
intstart_atCharacter position where extraction begins - negative counts from end
intend_atCharacter position where extraction ends - negative counts from end

Returns

TypeNameDescription
any...Numeric byte values for the specified range

Examples

Get the byte value of the first character
local byte = util.string.byte("A")

core.engine.print("info", byte) -- 65
Get the byte value at a specific position
local byte = util.string.byte("ABC", 2)

core.engine.print("info", byte) -- 66
Get multiple byte values at once
local b1, b2, b3 = util.string.byte("ABC", 1, 3)

core.engine.print("info", b1, b2, b3) -- 65  66  67
Use a negative index to read from the end
local last = util.string.byte("Hello", -1)

core.engine.print("info", last) -- 111 (character 'o')

On this page