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