如何在Lua中将字符编码转换为字符串字符?
例如:
例如:
d = 48
-- this is what I want
str_d = "0"
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.
针对您的例子:
local d = 48
local str_d = string.char(d) -- str_d == "0"
对于ASCII字符,您可以使用string.char
。
对于UTF-8字符串,您可以使用utf8.char
(在Lua 5.3中引入)以获取其代码点的字符。
print(utf8.char(48)) -- 0
print(utf8.char(29790)) -- 瑞