I'm trying to iterate through some pre-typed text in a Richtextbox and change the color of specific words/lines to a color depending on their prefix, thus far the different prefix's are [b], [f], and [e]. In this example I only use [b]. I've tried using while/foreach loops but they don't seem to iterate through the text. Below is the closest I've come to making it work but it only works on the first line of text. Any chance someone can point me in the correct direction?
private void AboutBox_Load(object sender, EventArgs e)
{
textBox1.Select(0, 0);
using (StringReader reader = new StringReader(richTextBox1.Text))
{
string line = string.Empty;
do
{
line = reader.ReadLine();
if ((line != null && line.Contains("[b]")))
{
richTextBox1.Select(richTextBox1.Text.IndexOf("[b]"), "[b]".Length);
richTextBox1.SelectionColor = Color.Green;
}
} while (line != null);
}
}