function string_split(str, delimiter)
if str == nil or str == ‘‘ or delimiter == nil then
return nil
end
local result = {}
for match in (str..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end
local tbl = string_split("aaaaacdddddzzzz", "c")
for k, v in pairs(tbl) do
print(k ,v )
end
输出结果:
> dofile "123.lua"
1 aaaaa
2 dddddzzzz
>
时间: 2024-12-18 13:26:38