spellcheck32
A .NET wrapper around the Microsoft Spell Checking API
Example
string text = "Cann I I haev some Linux?";
using SpellChecker spellChecker = new("en-US");
spellChecker.AutoCorrect("Linux", "Windows");
Console.WriteLine(string.Concat("Check \"", text, "\"", Environment.NewLine));
foreach (SpellingError error in spellChecker.Check(text))
{
string mistake = text.Substring(error.StartIndex, error.Length);
switch (error.CorrectiveAction)
{
case CorrectiveAction.Delete:
Console.WriteLine(string.Concat("Delete \"", mistake, "\"", Environment.NewLine));
break;
case CorrectiveAction.GetSuggestions:
Console.WriteLine(string.Concat("Suggest replacing \"", mistake, "\" with:"));
foreach (string suggestion in spellChecker.Suggest(mistake))
{
Console.WriteLine(string.Concat("\"", suggestion, "\""));
}
Console.WriteLine(string.Empty);
break;
case CorrectiveAction.Replace:
Console.WriteLine(
string.Concat("Replace \"", mistake, "\" with \"",
spellChecker.Suggest(mistake).First(), "\"", Environment.NewLine));
break;
case CorrectiveAction.None:
default:
break;
}
}
Output:
Check "Cann I I haev some Linux?"
Replace "Cann" with "Can"
Delete "I"
Replace "haev" with "have"
Replace "Linux" with "Windows"
API
namespace spellcheck32;
public class SpellChecker
{
public event EventHandler<EventArgs>? SpellCheckerChanged;
public string Id { get; }
public string LanguageTag { get; }
public string LocalizedName { get; }
public SpellChecker(string languageTag)
public void Add(string word)
public void AutoCorrect(string from, string to)
public IEnumerable<SpellingError> Check(string text)
public IEnumerable<SpellingError> ComprehensiveCheck(string text)
public void Ignore(string word)
public bool IsLanguageSupported(string languageTag)
public void RegisterUserDictionary(string dictionaryPath, string languageTag)
public void Remove(string word)
public IEnumerable<string> Suggest(string word)
public IEnumerable<string> SupportedLanguages()
public void UnregisterUserDictionary(string dictionaryPath, string languageTag)
}