我要搜索Unicode whitespace chars使用Lua在文件中。对于 ASCII,我们可以使用 %s
但我没有找到任何可以在 Unicode 文件中搜索空白字符的内容。
最佳答案
Lua 5.2 及更早版本对 Unicode 的支持很少。
(即将推出)Lua 5.3提供了一个基本的UTF-8库。但是,它仍然不知道该字符的含义(例如什么是空白字符)。在使用 utf8.codes
迭代每个代码点后,您需要自己完成该部分。 .
--table to be filled
local whitespace = {0x9, 0xA, 0xB, 0xC, 0xD, 0x20, 0x85, 0xA0, 0x1680, 0x2000, 0x2001}
local str = 'hello\u{2000}world\n'
for _, c in utf8.codes(str) do
for _, v in ipairs(whitespace) do
if c == v then
print 'whitespace found'
end
end
end
关于unicode - 如何在Lua中搜索Unicode空白字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23355626/