Code Spell Checker Class

Is there a way to check the spelling in the code?

I can only find how to use it with UI control

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

      

I want to boolean CheckSpell(string word)

I don't even need to suggest spelling.

This will be used to determine the percentage of correctly spelled words in the text file.
The real low number text file is probably not intended for human consumption.

The application has an SQL end, so loading the word into the Englich dictionary is an option.

+3


source to share


1 answer


To solve your problem, you can use NHunspell library .

Your validation method in this case is very simple and looks like this:

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

      



You can find dictionaries on this site .

Also you can use the SpellCheck

class:

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

      

+2


source







All Articles