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?
闭关修行中......
Use ASCII code to judge
var i = 0; var num=0; while (i<str.length) { if(str.charCodeAt(i) < 256) { num++ } else{ num+=2; } i++; } console.log(num)
Use ASCII code to judge