string.split = function(s, p)ip
local rt= {}
string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end )
return rtstring
endit
使用例子一io
local str = 'abc,123,hello,ok'table
local list = string.split(str, ',')function
for _, s in ipairs(list) dotab
print(s)return
end ab
結果:
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