> 
> **Possible Duplicate:**  
> 
> [How do i color a specific part of text in a richTextBox?](https://stackoverflow.com/questions/12854031/how-do-i-color-a-specific-part-of-text-in-a-richtextbox) 
> 
> 
> 

I have this function:

```
private void richTextBoxLoadKeys(Dictionary<string, List<string>> dictionary, string FileName)
        {
            string line = System.String.Empty;
            using (StreamReader sr = new StreamReader(keywords))
            {
                while ((line = sr.ReadLine()) != null)
                {
                    string[] tokens = line.Split(',');
                    dictionary.Add(tokens[0], tokens.Skip(1).ToList());
                    richTextBox2.AppendText("Url: " + tokens[0] + " --- " + "Localy KeyWord: " + tokens[1]+Environment.NewLine);
                    AppendText(richTextBox2, "Url: ", Color.Red);
                }
                sr.Close();
            }
        }

```

And i have the function AppendText:

```
public void AppendText(RichTextBox box, string text, Color color)
        {
            box.SelectionStart = box.TextLength;
            box.SelectionLength = 0;
            box.SelectionColor = color;
            box.AppendText(text);
            box.SelectionColor = box.ForeColor;
        } 

```

In the richTextBox i have for example:

```
Url: http://www.google.com --- Localy KeyWord: google
Url: http://www.cnet.com --- Localy KeyWord: cnet
Url: http://www.g.com --- Localy KeyWord: g

```

The result when trying to color it to Red is that the first Url: is in black then the two after it are in Red and then in the end its adding a new line only with Url: in Red.

What i wanted to do is to color in Red the Url: the link it self in yellow the --- in green the localy keyword: in pink and the google or cnet or g in blue.

I want each part of the Text in each line to be in a another Color.

Solved it:

```
void AppendText()
        {

            int len = this.richTextBox2.TextLength;
            int index = 0;
            int lastIndex = this.richTextBox2.Text.LastIndexOf("Url: ");

            while (index < lastIndex)
            {
                this.richTextBox2.Find("Url: ", index, len, RichTextBoxFinds.None);
                this.richTextBox2.SelectionColor = Color.Red;
                index = this.richTextBox2.Text.IndexOf("Url: ", index) + 1;
            }
        }

```