Numbers, letters, and space symbols represent one digit, and Chinese characters represent two digits. How to write a function to calculate the number of digits?
PHP中文网2017-05-19 10:15:45
var i = 0;
var num=0;
while (i<str.length) {
if(str.charCodeAt(i) < 256) {
num++
}
else{
num+=2;
}
i++;
}
console.log(num)