开发者

is there any library function for word counting in c#..?

开发者 https://www.devze.com 2023-03-14 05:23 出处:网络
I am wondering is there any functions in c# that helps to count number of words,sentences in a file...开发者_JS百科?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号