Probably existing libraries like Hunspell (already quoted in the chosen answer) or Aspell will solve your problem quickly: these libraries exist for several languages and are used in several programs.
But if you want to dig a little deeper: there is an excellent article by Peter Norvig (Google’s Director of Research) on the subject: http://norvig.com/spell-correct.html
Sure, it’s in English, but it explains in a basic way how the Google broker works when we use the search engine and it suggests a fix.
In summary: the system is based on a dictionary with Hamming Code verification of distance 2. In the case of the article and the examples, the dictionary is a file with enough text, where these are correctly written. Peter Norvig used several Shakespeare texts for this.
When the user enters a word, the program takes this word, and sees if it exists in the dictionary. If so, the word is correct.
If it does not exist, it generates several mutants (variations with error), of this word using the following techniques:
- Change the position of the next letters;
- Take one of the letters for each position;
- Insert a letter in each position;
- Delete a letter at each position.
From this list of mutants, he will check if any of them exist in the dictionary. The one that exists in the greatest number, will be the correct.
In the sample program, if you still can’t find a correct word, it takes every word from the mutant list, and it generates new mutants. And again see if any of them exist in the dictionary.
In the end of article, has the code of the program in several languages (at the time, I wrote a version in Java and Groovy) but you will see versions for virtually all languages, including two versions in C#.
The only additional detail is that you may have to tweak the source code so that the letter range is not just a-z, but also include accented letters, as we use in English.
And of course, you’ll need a dictionary in Portuguese. Or, optionally, if your list is composed only of products, for example, you can use, instead of the dictionary, your product list.
See if it suits you: Aspell.Net (Note: the Portuguese version is licensed via GPL - which can be problematic to integrate into your system depending on the case)
– mgibsonbr
You can work with a Word . dll to perform such fixes. Check this link out: http://www.codeproject.com/Articles/2469/SpellCheck-net-spell-checking-parsing-using-C
– Matheus Bessa
Just remember that the answers are interesting to use With Winforms. WPF has spell checking by default on its components where this is relevant.
– Maniero
Your answer sounds interesting, but today it is totally dependent on the link. And if he’s off the air, the answer becomes useless to the reader. If you improve it to include more detailed explanations on how to use Word DLL (no problem copying/translating Codeproject data as you cite the original source) and even some snippets of code, you get my +1. :)
– Luiz Vieira