Search for words and change their color [Archive] - C Board

PDA

View Full Version : Search for words and change their color


Coding
03-21-2008, 06:25 PM
If you have a richTextBox that contains these words.
What is the best/good way to do, if I want to change the color of the word "hello" to Ex: red.
Is there any searchfunction that can select multiple words etc...
I am trying to find a way to do this.


one two three hello
five hello
hello

DanFraser
03-26-2008, 07:22 AM
I have a complete mind block on the actual code, but know the process... (!)

Put all the richTextBox contents in to a string, replace search term in string with the word itself and the formatting needed.

ie. (but not actually this! This example replaces the term wanted with a bolded word in html format)


public static void ReplaceText(string myTerm)
{
string myString = richTextBox1.Text;
myString.Replace(myTerm, "<b>"+myTerm+"<\b>");
richTextBox1.Text = myString;
}


Then you can just feed in whatever term you want ("hello") like so:


ReplaceText("hello");


I'm bored, needed to do something random...