javascript 返回字符长度,中文为两个字节,英文为一个字节

//正则:用于区分中文为两个字节
function getLength(str){
    return String(str).replace(/[^x00-xff]/g,'aa').length;
}

输入:

abc:返回3

测试:返回4

原文地址:https://www.cnblogs.com/kgdxpr/p/5264708.html