您的位置:首页 > 编程语言 > Lua

Lua String 的扩展函数

2016-02-23 18:07 435 查看
字符串分割函数返回 Table

string.split = function(line, sep)

sep = sep or ' '

local retval = {}

local pos = 1

while true do

local from, to = string.find(line, sep, pos)

if from then

local item = string.sub(line, pos, from-1)

table.insert( retval, item )

pos = to + 1

else

local item = string.sub(line, pos)

table.insert( retval, item )

break

end

end

return retval

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: