I’ve got a RichTextBox, and would like to highlight a whole word, given just its ending index. Is it possible to highlight from an ending index, backwards to the first occurance of a space?
This is what I’ve tried so far, but I don’t know if there is any other efficient methods:
int length = richTextBox.Text.Reverse().Skip(richTextBox.Text.Length - offset)
.TakeWhile(x => x != ' ')
.Count();
richTextBox.Select(offset - length, length + 1);
richTextBox.SelectionBackColor = Color.Yellow;
That’s a very inefficient way to get the length.
Try this- might be off by one somewhere, I cant test it right now: