判断字符长度

function GetStringLength(str){
var realLength = 0, len = str.length, charCode = -1;
for (var i = 0; i < len; i++) {
charCode = str.charCodeAt(i);
if (charCode >= 0 && charCode <= 128) realLength += 1;
else realLength += 2;
}
return realLength;
}
posted @ 2017-06-02 16:13  千年鱼  阅读(167)  评论(0编辑  收藏  举报