Remember the Word Count function in Microsoft Word? Here’s how we could implement counting the words in a String in C#:
The following is the spource code of a program featuring two word counting methods, both of which yield fairly similar results to Microsoft Word from Microsoft Office 2007. The example program below first executes a Regex-based function for counting the words in the string constant, and then executes the loop-based one.