Benny Sutton is 4 hire - just click here

Extension method to get a word count

Count the number of words in a string using regular expressions. e.g. "the quick brown fox" returns 4

           
        public static int WordCount(this String str)
        {
            return str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries).Length;
        }

    

Extension methods are easy to chain, simply call like this...

         
         int count = strWords.WordCount();