Trying to select and color a specific word in WPF Richtextbox but my method selects just first 5 letters of the word. Indexes 0,1 and 2 seems to be empty string although the first word in my rtb is "private" and there is no empty string before it.

What can be the cause of this problem?

```
public  void FormatRtbText(RichTextBox rtb)
    {
        int x, y;
        string str = "private";

        var text = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd).Text;

        x = text.IndexOf(str);
        y = x + str.Length;

        var range = new TextRange(rtb.Document.ContentStart.GetPositionAtOffset(x), rtb.Document.ContentStart.GetPositionAtOffset(y));
        range.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Red);

    }

```