lua 字符串分割
function StringTool:stringSplit(str, splitChar)
local sub_str_tab = {};
while (true) do
local pos = string.find(str, splitChar);
if (not pos) then
local size_t = table.getn(sub_str_tab)
table.insert(sub_str_tab,size_t+1,str);
break;
end
local sub_str = string.sub(str, 1, pos - 1);
local size_t = table.getn(sub_str_tab)
table.insert(sub_str_tab,size_t+1,sub_str);
local t = string.len(str);
str = string.sub(str, pos + 1, t);
end
return sub_str_tab;
end
本文介绍了一个实用的Lua函数,用于将字符串按指定字符进行分割,并返回一个包含所有子串的表格。通过逐步解析代码实现过程,帮助读者理解其工作原理。
314

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



