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
>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-11-21
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
相关资源
相似解决方案