I am using C# Winforms with a rich text box. I am using the find method to highlight a word inside the text, basically for a spell checker. The problem I am having is that I do not wish to highlight a word if it is contained inside another word. Here is an example:
Text = This is an erro. This is a second erro.
Searching for “erro” in the string. The first error is corrected to “error”
Text = This is an error. This is a second erro.
Now when I search for “erro” it highlights it like:
this is an *erro*r. This is a second erro.
Is it possible to actually only highlight the word only if it is not contained inside another word? Or in other words is it possible to check to see if it is contained inside another so it can be skipped?
// Find the word.
ocrText.Find(this.ocrWords[wordToFindIndex], index, ocrText.TextLength, RichTextBoxFinds.None);
//TODO: Check to see if the found word is not contained inside another word
Thanks.
You should use the overloaded RichTextBox.Find method with the RichTextBoxFinds Enumeration
Specifically RichTextBoxFinds.WholeWord.