string.split = function(s, p)
local rt= {}string.gsub(s, '[^'..p..']+', function(w) table.insert(rtlist, w) end )
return rt
end
使用例子一
local str = 'abc,123,hello,ok'
local list = string.split(str, ',')
for _, s in ipairs(list) do
print(s)
end
结果:
abc
123
hello
ok
使用例子二
local str = 'abc \n123 \t hello ok'
local list = string.split(str, '%s')
for _, s in ipairs(list) do
print(s)
end
结果:
abc
123
hello
ok