lua中字符串的分割函数

function str_split(s, c)
        if not s then return nil end

        local m = string.format("([^%s]+)", c)
        local t = {}
        local k = 1
        for v in string.gmatch(s, m) do
                t[k] = v
                k = k + 1
        end
        return t

end


其中s为字符串

c为分割标识

t是一个table,存放分割后的结果

你可能感兴趣的:(函数,lua)