美文网首页
Lua 分割字符串

Lua 分割字符串

作者: 菜鸟的笔记 | 来源:发表于2019-07-30 21:30 被阅读0次
function 脚本名.split(str, split_char)      

    local sub_str_tab = {}

    while true do          

        local pos = string.find(str, split_char) 

        if not pos then              

            table.insert(sub_str_tab,str)

            break

        end  

        local sub_str = string.sub(str, 1, pos - 1)              

        table.insert(sub_str_tab,sub_str)

        str = string.sub(str, pos + 1, string.len(str))

    end      

 

    return sub_str_tab

end

相关文章

网友评论

      本文标题:Lua 分割字符串

      本文链接:https://www.haomeiwen.com/subject/tuborctx.html