function GetCharNewStrByLimit(str,limitCharNum)
local bytes = {str:byte(1,#str)}
local length,begin,cutByteLength = 0,false,0
for _, byte in ipairs(bytes) do
if byte < 128 or byte >= 192 then
begin = false
length = length + 1
elseif not begin then
begin = true
length = length + 1
if length > limitCharNum then
cutByteLength = cutByteLength - 1
end
else
if length > limitCharNum then
cutByteLength = cutByteLength + 1
end
end
if length <= limitCharNum then
cutByteLength = cutByteLength + 1
else
break
end
end
return string.sub(str,1,cutByteLength)
end
10-09
1万+
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交