我试图将字符串与unicode字符对齐。
但它不起作用。
空格不正确。 :(
Lua的版本为5.1。
这是什么问题?
使用Lua使用unicode字符进行字符串格式化
local t =
{
"character",
"루아", -- korean
"abc감사합니다123", -- korean
"ab23",
"lua is funny",
"ㅇㅅㅇ",
"美國大將", --chinese
"qwert-54321",
};
for k, v in pairs(t) do
print(string.format("%30s", v));
end
result:----------------------------------------------
character
루아
abc감사합니다123
ab23
lua is funny
ㅇㅅㅇ
美國大將
qwert-54321
格式化Unicode字符可能会非常棘手,因为每个字符不仅在编码时需要可变数量的字节,而且在显示时还会使用可变数量的列。对Luarocks进行快速搜索时,[wcwidth](https://luarocks.org/modules/aperezdc/wcwidth)库看起来与您正在尝试执行的操作相关。 – hugomg