G Guest May 22, 2004 #1 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?
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?
F Frank Eller [MVP] May 22, 2004 #2 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? Click to expand... 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
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? Click to expand... 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