How to count a selected words?

poringgunner

Active member
Joined
Feb 23, 2014
Messages
42
Programming Experience
Beginner
how can i count a selected words in a richtextbox? example i want to count a word "if" and show the result foreach (char q in richTextBox1.Text) { if (char.IsWhiteSpace(q)) { newline++; } } foreach (char w in richTextBox2.Text) { if (char.IsWhiteSpace(w)) { newline++; } } thanks in advance.!
 
Last edited:
Huh? Firstly, please don't post unformatted code as it's virtually unreadable. Copy your code directly from the IDE if possible or else type it as it would appear in the IDE and use formatting tags, i.e.

[xcode=c#]your code here[/xcode]

As for the issue, I would suggest two options:

1. Use the String.Split method to create an array of words from the Text of the RTB. You can then either loop through that and test each word against your list of search terms or use a LINQ query.
2. Use a loop and String.IndexOf to find the end of each word and the String.Substring to take the word, then test it against your search terms.

Either way, you'll want to also remove punctuation characters from the words before testing them.
 
thank you sir. :) i helps a lot i use String.Split method only.. i dont know how to use String.IndexOf for loop although i know i need to use it.
 
Back
Top Bottom