lua字符串利用分隔符拆分

把一个字符串用某个特定的符号去拆分它

----

--用symbol分隔字符串str,返回分隔后字符串数组

--@param str string 要分隔的字符串

--@param symbol string 分隔符

--@return table 分隔后的字符串数组

function splitSymbol(str, symbol)

        local findStartIndex = 1

        local splitIndex = 1

        local splitedTable = {}

        while true do

                local nFindLastIndex = string.find(str, symbol, findStartIndex)

                if not nFindLastIndex then

                        splitedTable[splitIndex] = string.sub(str, findStartIndex, string.len(str))

                        break

                end

                splitedTable[splitIndex] = string.sub(str, findStartIndex, nFindLastIndex - 1)

                findStartIndex = nFindLastIndex + string.len(symbol)

                splitIndex = splitIndex + 1

        end

        return splitedTable

end

你可能感兴趣的:(lua,ios,android,xcode,java,开发语言)