util.string.char

Shared

Converts numeric codes to their corresponding characters


Syntax

local result = util.string.char(
    ...
)

Parameters

TypeNameDescription
any...Byte values to convert

Returns

TypeNameDescription
stringresultString composed of characters corresponding to the byte values

Examples

Create a string from byte values
local str = util.string.char(65, 66, 67)

core.engine.print("info", str) -- 'ABC'
Build a greeting string from byte values
local greeting = util.string.char(72, 101, 108, 108, 111)

core.engine.print("info", greeting) -- 'Hello'
Create a single character from a byte value
local char = util.string.char(33)

core.engine.print("info", char) -- '!'
Create an empty string with no arguments
local empty = util.string.char()

core.engine.print("info", empty) -- ''
Round-trip a string through byte and char
local bytes = {util.string.byte("Hi", 1, -1)}
local reconstructed = util.string.char(util.table.unpack(bytes))

core.engine.print("info", reconstructed) -- 'Hi'

On this page