信息发布→ 登录 注册 退出

Lua实现split函数

发布时间:2026-01-11

点击量:
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

标签:# brush  # pos  # start  # return  # local  # table  # insert  # break  # find  # plain  # lt  # cpp  # function  # Lua  # pre  # class  # string  # len  # type  # split  # delim  # Lua中if语句嵌套的使用教程  # C调用lua函数需要考虑的问题  # Lua教程(二):基础知识、类型与值介绍  # split函数  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!