js统计包含中文的字符长度,一个汉字算两个字符
来源:原创
时间:2017-05-16
作者:脚本小站
分类:JS/JQuery
统计包含中文的字符长度,一个汉字算两个字符
String.prototype.len=function(){return this.replace(/[^\x00-\xff]/g,"aa").length;}
只统计中文
var pattern_chin = /[\u4e00-\u9fa5]/g;
var count_chin = tempStr.match(pattern_chin).length;