c# - How to search for a phrase in a RichTextBox and highlight every instance of that phrase with a color you specify -


how can 1 search phrase in richtextbox , highlight every instance of phrase color desired?

replace string assigned valtosearchfor , color assigned richtextbox's selectioncolor property desired.

string richtext = richtextbox1.text; string valtosearchfor = "duckbilledplatypus"; int pos = 0; pos = richtext.indexof(valtosearchfor, 0); while (pos != -1) {     richtextbox1.select(pos, valtosearchfor.length);     richtextbox1.selectioncolor = color.red;     pos = richtext.indexof(valtosearchfor, pos + 1); } 

Comments