function FormotGameNickName(nickname,length)
if nickname==nil then
return ""
end
local lengthUTF_8 = #(string.gsub(nickname, "[\128-\191]", ""))
if lengthUTF_8 <= length then
return nickname
else
local matchStr = "^"
for var=1, length do
matchStr = matchStr..".[\128-\191]*"
end
local str = string.match(nickname, matchStr)
return string.format("%s...",str);
end
end
local nameString = "嗎,xc d$f按菿氺電費"
local ok, ss = pcall(FormotGameNickName, nameString,6)
if ok then
print(ss,string.len(ss))
else
print("split nickname fail")
end
lua 截取中英文字符串
最新推荐文章于 2022-10-22 22:41:16 发布