function UITool.getCharLength(str)
str = str or ""
local strLength = 0
local len = string.len(str)
while str do
local fontUTF = string.byte(str,1)
if fontUTF == nil then
break
end
--lua中字符占1byte,中文占3byte
if fontUTF > 127 then
local tmp = string.sub(str,1,3)
strLength = strLength+1
str = string.sub(str,4,len)
else
local tmp = string.sub(str,1,1)
strLength = strLength+1
str = string.sub(str,2,len)
end
end
return strLength
end
Lua中获取字符长度
猜你喜欢
转载自blog.csdn.net/qq_25563175/article/details/84834886
今日推荐
周排行