字符串分割函数返回 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

本文介绍了一个用Lua编写的字符串分割函数,该函数可以将输入的字符串根据指定的分隔符进行分割,并返回一个包含所有分割后子串的表格。文章详细展示了函数的实现过程。
1098

被折叠的 条评论
为什么被折叠?



