Posted By

Sootah on 02/12/11


Tagged


Versions (?)

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  

You need to login to post a comment.