c# - 后面代码中的拼写检查类

标签 c# .net spell-checking

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

我只能找到如何通过 UI 控件使用它

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

我要的是boolean CheckSpell(string word)

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

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

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

最佳答案

要解决您的问题,您可以使用 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;
}

关于c# - 后面代码中的拼写检查类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14541038/

相关文章:

c# - IEnumerable<string> System.ObjectDisposedException

.net - 如何使用自定义结构代替 KeyValuePair?

c# - div 内容丢失

delphi - 如何使用 Delphi 并行检查拼写?

macos - 更改 NSTextField 运行时中拼写检查的语言

ruby-on-rails - 使用 TinymceSpellcheck 时出现 ArgumentError

c# - 如何在没有 Entity Framework 的情况下连接到 ASP.NET Core 中的数据库?

c# - C# 中的 ANSI 与 SHIFT JIS 与 UTF-8

C#获取数据包

c# - 如何使 Razor View 引擎使用 C# 6.0