If there is a random string get from SERVER:
var str='I am a student in XXX university, I am interested...'
The str can contain random number of words with spaces. That’s the content of the string is unpredictable.
In javascript, how to count the number of letters in the string (spaces between words are exclusive from the counting). For example “I have a car” should be counted 9 letters.
Assuming you only want alpha characters, get rid of other characters first using
replace():You can add
0-9to the[^A-Z]character class if you want to count numbers as letters. If you only want to remove white-space, change the regular expression to/\s/g