formatName: function (str) {
if (typeof(str) == "undefined" || str == null) {
return "";
}
if (typeof(str) != "string") {
return "";
}
let bytesLen = str.replace(/[^\x00-\xff]/g, 'xx').length;
if (bytesLen > 6) {
let index = 0;
let byteLen = 0;
for ( var i = 0; i < str.length; i++) {
if (str.charCodeAt(i) > 255) {
byteLen += 2;
} else {
byteLen += 1;
}
if(byteLen >= 6 ){
index = i;
break;
}
}
str = str.substr(0, index+1);
str = str + "..."
}
//cc.log(str, "str+++++++++++++++++ = = ")
return str;
},
JS截取字节
最新推荐文章于 2023-05-18 09:21:21 发布