Reputation: 550
I am wondering is there any functions in c# that helps to count number of words,sentences in a file...?
Now I used the following code is it efficient/error free?
string[] words=datafromfile.Split(' ');
int numberofwords=words.GetUpperBound(0)
Thank you
Upvotes: 2
Views: 444
Reputation: 35126
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
Upvotes: 1