Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert a character code to a string character in Lua?

Tags:

string

lua

How can I convert a character code to a string character in Lua?

E.g.

d = 48
-- this is what I want
str_d = "0"
like image 724
Aftershock Avatar asked Oct 18 '25 11:10

Aftershock


1 Answers

You are looking for string.char:

string.char (···)

Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument.

Note that numerical codes are not necessarily portable across platforms.

For your example:

local d = 48
local str_d = string.char(d) -- str_d == "0"

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!