Posted By

Sootah on 02/12/11


Tagged


Versions (?)

Last Edited at 02/12/11 12:52pm

Viewed 1 times

wordCount - RegEx count the number of words in a string


/ Published in: C#


  1. using System.Text.RegularExpressions;
  2.  
  3. public int WordCount(string txtToCount)
  4. {
  5. string pattern = "\\w+";
  6. Regex regex = new Regex(pattern);
  7.  
  8. int CountedWords = regex.Matches(txtToCount).Count;
  9.  
  10. return CountedWords;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.