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!
Asked
Active
Viewed 1,087 times
-1
-
Is this in ASP.NET, Winforms, WPF?... – Brad Jun 21 '16 at 16:28
-
Have you seen this? https://msdn.microsoft.com/en-us/library/system.windows.controls.spellcheck(v=vs.110).aspx – Brad Jun 21 '16 at 16:32
-
1There is more than a certain degree of irony in this question. http://www.dictionary.com/browse/misspelled – PaulF Jun 21 '16 at 16:46
-
Thanks Brad, I did see that while I was searching the web. Do you know how I would auto correct it? – inavnacorp Jun 21 '16 at 17:38
1 Answers
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