1. RegEx. Matches (S, @ "[A-Za-z0-9] [A-Za-z0-9 '\-.] *"). Count)
RegEx. Matches (S, @ "[A-Za-z0-9] [A-Za-z0-9 \-.] *"). Count (English word conjunction is not a word)
2. String [] STR = filterhtml (content). Split ("~! @ # $ % ^ & * () _ +-= '| \: \ "?> <; ',./". Tochararray ());
Int I = 0;
Foreach (string s in Str)
{
If (S. Length = 0)
I ++;
}
Count = Str. Length-I;
The disadvantage of the 2nd method is that the number of words cannot be counted. For example, 123.456 is used as two words. The above method is only applicable to the number of words in English.
3. RegEx. Matches (txtcontent. Text, @ "[\ W] +"). Count Chinese Characters
RegEx. Matches (strcontent, @ "[0-9] [0-9 '\-.] *"). Count Number of words
Chinese Word Count statistics:
Public static int chineselettercount (string strtext) {byte [] byts = system. Text. encoding. getencoding ("gb2312"). getbytes (strtext );
Return byts. Length-strtext. length;
}
The above are approximate statistics.
The English word count statistics have been very accurate, and the Chinese Word Count statistics have a large error and need to be improved.
However, I found a bug in word2010 statistics during the comparative test:
See the following test cases:
"I looked at it and said, 'we' ll be back in a few days, '" Byron Largent said of the China. (word2010 contains 20 words)
The regular statistics I wrote are 19. I don't know who is right or who is wrong.
Note: The join word is not counted as two. It seems that Microsoft does not count as one word.