javascript - Function to count the number of words?
阿神
阿神 2017-05-19 10:13:45
0
2
826

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?

阿神
阿神

闭关修行中......

reply all(2)
过去多啦不再A梦

Use ASCII code to judge

Ty80
var i = 0;
var num=0;
while (i<str.length) {
    if(str.charCodeAt(i) < 256) {
       num++
    }
    else{
       num+=2;
    }
    i++;
}
console.log(num)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template