js 计算字符串字节长度

_getByteLen(v) {
    var len = 0;
    for (var i = 0; i < v.length; i++) {
        var a = v.charAt(i);
        if (a.match(/[^\x00-\xff]/ig) != null)
        {
            len += 2;
        }
        else
        {
            len += 1;
        }
    }
    return len;
}

 

 

摘自:https://blog.csdn.net/qq_31393401/article/details/81978543

posted @ 2021-05-24 16:46  安静的女汉纸  阅读(159)  评论(0编辑  收藏  举报