Lua gfind问题

时间:2012-06-21 03:29:12

标签: lua

    testA = "test.test test.test"
    local t1 = {}
    for X in string.gfind (testA, "[^ ]+") do
    table.insert (t1 ,X)
    end
    local first = table.concat(t1, "", 1, 1);

    --output/first test.test

    testA = "11.11.11.11 test.test"
    local t2 = {}
    for X in string.gfind (testA, "[^ ]+") do
    table.insert (t2 ,X)
    end
    local first = table.concat(t2, "", 1, 1);

    --output/first 11.11.11.11

    testA = "100.100.100.100  test.test"
    local t3 = {}
    for X in string.gfind (testA, "[^ ]+") do
    table.insert (t3 ,X)
    end
    local first = table.concat(t3, "", 1, 1);

    --output/first 100.100.100.100    test.test

有谁知道为什么第3项不会与gfind分开? ,无法弄清楚为什么
它适用于两个字符串,但不适用于第三个。

1 个答案:

答案 0 :(得分:1)

您的问题是标签字符与空格不同。如果你想跳过所有空白字符,你需要实际跳过空格字符,而不仅仅是常规空格:

string.gfind (testA, "[%S]+")