cocos2dx 2.x环境,要做一个截取很长的字符串的前100个字符显示的小功能. PC环境ok,出了ios包发现有时候这个字符串会显示不出,猜测了下可能是跟中文字在lua里每个字占3个字符有关,举个例子: 原字符串"一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十",第100个字符是第四组第一个"一"的第一个字符,PC上显示会是一个小乱码,真机上可能就显示不正常了. local function getByteCount(str,
lua的string函数: 参数中的index从1开始,负数的意义是从后开始往前数,比如-1代表最后一个字母 对于string类型的值,可以使用OO的方式处理,如string.byte(s.i)可以被写成s:byte(i) It also sets a metatable for strings where the __index field points to the string table. Therefore, you can use the string functions in ob
--[[-- 用指定字符或字符串分割输入字符串,返回包含分割结果的数组 local input = "Hello,World" local res = string.split(input, ",") -- res = {"Hello", "World"} local input = "Hello-+-World-+-Quick" local res = string.split(input, "