<pre name="code" class="javascript"><pre name="code" class="plain">function LuaSplit(str, split_char)
if str == "" or str == nil then
return {};
end
local split_len = string.len(split_char)
local sub_str_tab = {};
local i = 0;
local j = 0;
while true do
j = string.find(str, split_char,i+split_len);--从目标串str第i+split_len个字符开始搜索指定串
if string.len(str) == i then
break;
end
if j == nil then
table.insert(sub_str_tab,string.sub(str,i));
break;
end;
table.insert(sub_str_tab,string.sub(str,i,j-1));
i = j+split_len;
end
return sub_str_tab;
end
local s = LuaSplit("王进,订单,阿第克,阿饼",",")
local i = 1
while true do
if s[i] then
print(s[i])
i = i+1
else
break
end
end
Lua切割中文字符串,按指定字符,切割字符串
最新推荐文章于 2024-02-22 08:59:07 发布