Lua实现split函数

这篇文章主要介绍了Lua实现split函数,lua中没有split分割字条串函数,本文使用自定义函数实现,需要的朋友可以参考下

 function split(s, delim) if type(delim) ~= "string" or string.len(delim) <= 0 then return end local start = 1 local t = {} while true do local pos = string.find (s, delim, start, true) -- plain find if not pos then break end table.insert (t, string.sub (s, start, pos - 1)) start = pos + string.len (delim) end table.insert (t, string.sub (s, start)) return t end

以上就是Lua实现split函数的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Lua