|
发表于 2020-5-4 15:34:29
|
显示全部楼层
重庆市重庆市
function split(str,length)
local strLen = #str;
local location = 0
local t={}
local str1=""
local str2=""
local num=0
for i = 1, strLen do
local getByte = string.byte(str, i);
local byteLen = 1;
if getByte > 0 and getByte <= 127 then
byteLen = 1
elseif getByte >= 192 and getByte < 223 then
byteLen = 2
elseif getByte >= 224 and getByte < 239 then
byteLen = 3
elseif getByte >= 240 and getByte <= 247 then
byteLen = 4
end
str1 = string.sub(str, i, i + byteLen - 1)
location = i + byteLen - 1;
if (i~= location or getByte < 127) then
str2=str2..str1
num=num+1
if (num==length) then
table.insert(t,str2)
num=0
str2=""
end
end
end
if (str2~="") then
table.insert(t,str2)
end
return t
end
t=split("123",1)
for i=1,#t do
print(t[i])
end |
评分
-
参与人数 1 | 荣誉 +1 |
收起
理由
|
笨潴
| + 1 |
热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻! |
查看全部评分
|