a implementacao basica do Soundex: // -> Obtem o soudex de uma string private static string GetSoundex(string value) { value = value.ToUpper(); // -> Normaliza letras em Maiuscula var result = new StringBuilder(); foreach (char item in value) if (char.IsLetter(item)) // -> Limpa String AddCharacter(result, item); // -> Adiciona um char Soudex // -> Limpa as excecoes geradas result.Replace(".", string.Empty); // -> Arruma o tamanho no padrao soudex // 4 caracteres. FixLength(result); return result.ToString(); } // -> Preenche com 0 nos casos menor q quatro, // ou pega os 4 primeiros caracteres. private static void FixLength(StringBuilder result) { var length = result.Length; if (length < 4) result.Append(new string('0', 4 - length)); else result.Length = 4; } // -> Adiciona o caractere soudex, cuidando para nao repetir. private static void AddCharacter(StringBuilder result, char item) { if (result.Length == 0) { result.Append(item); } else { var code = GetSoundexDigit(item); if (code != result[result.Length - 1].ToString()) result.Append(code); } } // -> Algoritmo de substituicao padrao Soudex. private static string GetSoundexDigit(char item) { var charString = item.ToString(); if ("BFPV".Contains(charString)) return "1"; else if ("CGJKQSXZ".Contains(charString)) return "2"; else if ("DT".Contains(charString)) return "3"; else if ("L".Contains(charString)) return "4"; else if ("MN".Contains(charString)) return "5"; else if ("R".Contains(charString)) return "6"; else return "."; }.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }Como a lingua portuguesa dispoes de muita sujeira e quinquilharia acentos e simbolos, temos de trata-las com as funcoes a seguir: // -> Recebe varias letras, separadas por virgula, para serem substituidas por uma letra especifica. private static string ReplaceMultiplo(string value, string from, string to) { var fromPattern = string.Format("({0})", string.Join(")|(", from.Split(','))).Replace(".", @"\."); return Regex.Replace(value, fromPattern, to); } private static string GetSoundexBR(string value) { value = value.ToUpper(); value = ReplaceMultiplo(value, "A,A,A,A,A", "A"); value = ReplaceMultiplo(value, "E,E,E,E", "E"); value = ReplaceMultiplo(value, "I,I,I,I", "I"); value = ReplaceMultiplo(value, "O,O,O,O,O", "O"); value = ReplaceMultiplo(value, "U,U,U,U", "U"); value = ReplaceMultiplo(value, ".,-,", string.Empty); value = ReplaceMultiplo(value, "0,1,2,3,4,5,6,7,8,9,0", string.Empty); value = ReplaceMultiplo(value, "Y", "I"); value = ReplaceMultiplo(value, "PH", "F"); value = ReplaceMultiplo(value, "GE", "JE"); value = ReplaceMultiplo(value, "GI", "JI"); value = ReplaceMultiplo(value, "CA", "KA"); value = ReplaceMultiplo(value, "CE", "SE"); value = ReplaceMultiplo(value, "CI", "SI"); value = ReplaceMultiplo(value, "CO", "KO"); value = ReplaceMultiplo(value, "CU", "KU"); value = ReplaceMultiplo(value, "C", "S"); value = ReplaceMultiplo(value, "WAS", "WS"); value = ReplaceMultiplo(value, "WA", "VA"); value = ReplaceMultiplo(value, "WO", "VO"); value = ReplaceMultiplo(value, "WU", "VU"); value = ReplaceMultiplo(value, "WI", "UI"); // -> Depois de tratar a lingua portuguesa // Geramos o soudex padrao. value = GetSoundex(value); return value; }.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op