I would like to know what exactly happen when we use myTextPointer.GetPositionAtOffset(int)
.
I am doing a search in a richTextBox using this code. I just don't understand why we need to be in a loop. I check in debug mode and most of the time when we do searchRange.Start.GetPositionAtOffset(offset + searchText.Length)
my textPointer didn't move, and my "searchText" had a length of 1 or more.
In the loop, result is mostly empty cause new TextRange(start, start.GetPositionAtOffset(searchText.Length)
has a range of offset 87 and 87 (example) even if searchText.Length
is higher then 0.
for(TextPointer start = searchRange.Start.GetPositionAtOffset(offset); start != searchRange.End; start = start.GetPositionAtOffset(1))
{
TextRange result = new TextRange(start, start.GetPositionAtOffset(searchText.Length);
if(result.Text == searchText)
return result;
}
Thanks