I am looking for a good word count class or function. When I copy and paste something from the internet and compare it with my custom word count algorithm and MS Word it is always off by a little more then 10%. I think that is too much . So do you guys know of an accurate word count algorithm in c#.
+2
A:
String.Split by predefined chars. Use punctuations, spaces (remove multiple space), and any other chars that you determine to be "word splits"
What have you tried?
I did see that the previous user got nailed for links, but here is some examples of using regex, or char matching. Hope it helps, and nobody gets hurt X-)
astander
2009-10-27 19:33:20
not for links, rather, for googling the obvious links w/ no value add brought in
zvolkov
2009-10-27 19:51:16
ok, point taken.
astander
2009-10-27 19:52:50
A:
As @astander suggests, you can do a String.Split as follows:
string[] a = s.Split(
new char[] { ' ', ',', ';', '.', '!', '"', '(', ')', '?' },
StringSplitOptions.RemoveEmptyEntries);
By passing in an array of chars, you can split on multiple word breaks. Removing empty entries will keep you from counting non-word words.
Larsenal
2009-10-27 19:44:27