is there any library function for word counting in c#..?
I am wondering is there any functions in c# that helps to count number of words,sentences in a file...开发者_JS百科?
Now I used the following code is it efficient/error free?
string[] words=datafromfile.Split(' ');
int numberofwords=words.GetUpperBound(0)
Thank you
You could use RegEx.Split
using the word boundary \b
instead.
You're not considering new lines as word boundaries. Full stop is also a word boundary. You should use regex for this. It has \b
Use int words = Regex.Split(yourText, "\b").Length
Not out of the box, but you can look at this.
精彩评论