End Google Ads 201810 - BS.net 01 --> Hello,
I want to search text in a WPF richTextBox. My problem is the text is formatted...

For a normal text I use this:

string wordToSearch = "word"; TextRange tr = new TextRange(this.rtb.Document.ContentStart, int startPos = tr.Text.IndexOf(wordToSearch); this.rtb.Document.ContentEnd); if (startPos > -1){ int l = this.GetLinesCount(tr.Text, startPosition); TextPointer startRtb = this.rtb.Document.ContentStart; TextPointer start = startRtb.GetPositionAtOffset(startPos + l); TextPointer end = start.GetPositionAtOffset(wordToSearch.Length); this.rtb.Selection.Select(start, end); this.rtb.Selection.ApplyPropertyValue( TextElement.BackgroundProperty, this.rtb.SelectionBrush);} public int GetLinesCount(string str, int startPosition){ int lines = str.Take(startPosition).Count(k => k.Equals((char)13) || k.Equals((char)10)); return lines + 2;}
But, for a formatted text (other color for example), I see a difference between my "word" and my "selection" of X characters.

If somebody has an idea?!?
Thank you for help me...
Bye.