c# WPF 拼写检查器,用于拼写错误的字符串。

c# WPF spell checker for misspelled word strings.

我正在寻找在单词拼写错误并且似乎是两个单词的组合时自动修复该单词的方法。例如 "considerationof" 应该是 "consideration of"。任何线索或任何例子都将不胜感激。谢谢!

试试这个来迭代你的拼写错误:

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);

这之后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 \"consideration of\" should be \"consideration of\". Any lead or any example will be greatly appreciated. Thanks!"

对第一个建议"auto-corrects"。这是否最终是您想要的,您必须做出决定。

将它放在 TextChanged 事件中可能不是一个好主意(您不希望它在完成输入之前更正单词)。也许 LostFocus 更合适。