Vital.sandbox
String

string.char

Shared

Converts numeric codes to their corresponding characters


Syntax

local result = string.char(...)

Parameters

TypeNameDescription
......Byte values to convert

Returns

TypeNameDescription
stringresultString composed of characters corresponding to the byte values

Examples

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

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

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

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

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

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

On this page