Question Locked

How to search several words in a RichEditBox with over 20,000 lines

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a speed performance issues. I would like to ask how would you guys do this.

I am using Visual Basic Net 2005 and am making a Programming Editor for our Healthcare software.

I use a RichTextBox to load a text file which will result in over 20,000 lines of text. Then i have to search each line for 10 or more specfic words. The result of the search will then appear in a tree-structure List control.

I use Richtextbox.find function to search for the words but it seems to be very slow. How would you improve the speed issues?

4 replies

by tony hopkinson

System.Text.RegularExpressions

It will take a while to get your head round them, but they are very clever and much faster then Ctrl-F in a component.

When you pass it the 20k lines get the straight text not the formatted version, there will be a big mass of ctrl characters in there to do colours and fonts etc.

If you want to use the Tree structure to jump to the text in the RTF control, you've a few more dandruff moments (head scratchers) to come.

by cecilcheah

Can Regular Expressions find the words in the 20K line of text and delete the rest, so just leaving the RichTextBox with the found words? Can you also give me a hint of the regular Expressions if i want to search for say Tech and Republic in the 20K line of text and delete the rest of the text? I am not very good at Regular Expressions.

Thanks in advance.

by evildictaitor1

Firstly, RegExps' can do this. Secondly they are NOT faster than CTRL-F find, since RegExp's are a complex algorithm for finding, used for conveniance.

The reason your program is slow is because you are loading the thing into a RichTextControl, which has a HUGE overhead in terms of memory usage. Instead, if your stuff is in a file C:/myFile.txt,

string s = System.IO.File.ReadAllText("C:/myFile.txt");
int index = s.IndexOf("searchFor");
if(index != -1){
MessageBox.Show("Found term at charpos "+index);
}else{
MessageBox.Show("Didn't find the search Term.");
}

This discussion is closed to new replies.