Word Count

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to add word count to my application. Consider the textcontrol as a regular Windows Forms Rich Text Box. How would I go about counting words?
 
Hi Bill,

I want to add word count to my application. Consider the textcontrol
as a regular Windows Forms Rich Text Box. How would I go about
counting words?

Try Regular Expressions, for example:

========================

string pattern = "\b(\S+)\b"
int wordCount = Regex.Matches( richTextBox1.Text, pattern,
RegexOptions.None ).Count;

========================

There's more than one way to to it, but the Regex here should be ok to do
the job. Don'T forget to import the Namespace
System.Text.RegularExpressions.

Regards,

Frank Eller
 
Back
Top