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

ina*_*orp -1 c# wpf spell-checking

我正在寻找自动拼写一个单词的方法,如果该单词拼写错误并且似乎是两个单词的组合。例如,“ considerationof”应为“ consideration of”。任何线索或任何示例将不胜感激。谢谢!

Bra*_*rad 5

尝试执行以下操作以遍历您的拼写错误:

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);
Run Code Online (Sandbox Code Playgroud)

tb.Text运行后的值是

“如果单词拼写错误并且似乎是两个单词的组合,我正在寻找自动修复单词的方法。例如,\“考虑\”应为\“考虑\”。任何线索或任何示例都将非常感谢。谢谢!”

它会“自动更正”第一个建议。最终这是否是您想要的,您必须决定。

将其放在TextChanged事件上可能是一个坏主意(您不希望它在完成良性输入之前纠正单词)。也许像这样LostFocus更合适。