Count number of word in text in c#.

How to count number of word in text. Below function will return number of word in text.

        public static int CountNoWordsInString(string text)
        {
            if (String.IsNullOrEmpty(text))
            { 
               return 0; 
            }
            var tmpStr = text.Replace("\t", " ").Trim();
            tmpStr = tmpStr.Replace("\n", " ");
            tmpStr = tmpStr.Replace("\r", " ");
            while (tmpStr.IndexOf("  ") != -1)
              {
                tmpStr = tmpStr.Replace("  ", " ");
              }
            return tmpStr.Split(' ').Length;
        }

Page Keyword: Word count in text, total number of word in Text, count word in text in c#, word count program in text, Find number of word in text code , Number of word in text by c# program. total word count in umbraco. word count in text program.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s