【问题标题】:SpellCheck Class In Code Behind代码后面的拼写检查类
【发布时间】:2013-01-26 20:01:36
【问题描述】:

有没有办法检查代码中的拼写?

我只能找到如何与 UI 控件一起使用它

<TextBox SpellCheck.IsEnabled="True" Height="20" Width="100"/>

我想要的是boolean CheckSpell(string word)

我什至不需要建议的拼写。

这将用于确定文本文件中正确拼写单词的百分比。
具有真正低数字的文本文件可能不适合人类使用。

该应用具有 SQL 后端,因此可以选择加载英语词典中的单词列表。

【问题讨论】:

  • 您可以在没有 UI 的情况下创建 TextBox 类实例。

标签: c# .net spell-checking


【解决方案1】:

要解决您的问题,您可以使用NHunspell 库。

您在本例中的检查方法非常简单,如下所示:

bool CheckSpell(string word)
{         
    using (Hunspell hunspell = new Hunspell("en_GB.aff", "en_GB.dic"))
    {
        return hunspell.Spell(word);               
    }
}

你可以在this site找到字典。

你也可以使用SpellCheck类:

bool CheckSpell(string word)
{
    TextBox tb = new TextBox();
    tb.Text = word;
    tb.SpellCheck.IsEnabled = true;

    int index = tb.GetNextSpellingErrorCharacterIndex(0, LogicalDirection.Forward);
    if (index == -1)
        return true;
    else
        return false;
}

【讨论】:

  • 谢谢 你有推荐的吗?速度是一个因素,因为我会检查超过 100 万个单词。
  • 不客气。你必须检查它。我没有进行性能测试。
  • 好的。如果我的 SpellCheck 性能良好,我会坚持下去,因为它是一次性批次。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多