有没有办法检查代码后面的拼写?
我只能找到如何通过 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/