function byteLength(str) {
var byteLen = 0, len = str.length;
if( !str ) return 0;
for( var i=0; i<len; i++ )
byteLen += str.charCodeAt(i) > 255 ? 2 : 1;
return byteLen;
}
js计算字符串字节长度
最新推荐文章于 2023-12-29 15:35:02 发布
function byteLength(str) {
var byteLen = 0, len = str.length;
if( !str ) return 0;
for( var i=0; i<len; i++ )
byteLen += str.charCodeAt(i) > 255 ? 2 : 1;
return byteLen;
}

被折叠的 条评论
为什么被折叠?