2

Lua を使用して、ファイル内のUnicode 空白文字を検索したいと思います。ASCII の場合は使用できます%sが、Unicode ファイルで空白文字を検索するものは見つかりませんでした。

4

1 に答える 1

3

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
于 2014-04-29T06:52:55.557 に答える