-1

I am looking for ways to automatically fix a word if the word is miss spelled and seems to be a combination of two words. For example "considerationof" should be "consideration of". Any lead or any example will be greatly appreciated. Thanks!

inavnacorp
  • 83
  • 1
  • 1
  • 7

1 Answers1

5

Try this for iterating over your spelling mistakes:

TextBox tb = new TextBox();
tb.SpellCheck.IsEnabled = true;
tb.Text = @"I am looking for ways to automatically fix a word if the word is miss spelled and seems to be a combination of two words. For example ""considerationof"" should be ""consideration of"". Any lead or any example will be greatly appreciated. Thanks!";

var spellingErrorIndex = tb.Text.Length;
do
{

    var spellingError = tb.GetSpellingError(spellingErrorIndex);
    if (spellingError != null)
    {
        var suggestions = spellingError.Suggestions;    //suggests "consideration of"
        spellingError.Correct(suggestions.First());
    }

    spellingErrorIndex = tb.GetNextSpellingErrorCharacterIndex(spellingErrorIndex, LogicalDirection.Backward);
} while (spellingErrorIndex >= 0);

The value of tb.Text after this is run is

"I am looking for ways to automatically fix a word if the word is miss spelled and seems to be a combination of two words. For example \"consideration of\" should be \"consideration of\". Any lead or any example will be greatly appreciated. Thanks!"

It "auto-corrects" to the first suggestion. Whether that is ultimately what you want or not you'll have to decide.

It would probably be a bad idea to put this on a TextChanged event (you don't want it correcting words before they've finished beign typed). Maybe something like LostFocus is more appropriate.

Brad
  • 11,934
  • 4
  • 45
  • 73