cocos lua 汉字字符

版权声明:转载请声明 https://blog.csdn.net/twicetwice/article/details/82145683
--汉字算两个字符,其他算一个

local function CountSign(text)
	local count = 0

 	for uchar in string.gmatch(text, "([%z\1-\127\194-\244][\128-\191]*)") do 
	    if #uchar ~= 1 then
	    	count = count +2
	    else
	      count = count +1
	    end
    end 
    return count
end

猜你喜欢

转载自blog.csdn.net/twicetwice/article/details/82145683