假设:一个英文字符占用一个字节,一个中文字符占用两个字节

function GetBytes(str){
    var len = str.length;
    var bytes = len;
    for(var i=0; i<len; i++){
        if (str.charCodeAt(i) > 255) bytes++;
    }
     return bytes;
}
alert(GetBytes("你好,as"));

相关文章:

  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
猜你喜欢
  • 2021-09-04
  • 2021-06-22
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案