This does not tell you where your code is going wrong, and probably not even the fastest solution, but it seems to fit correctly and has only a few lines of code.
It implements the six steps of the second version of the algorithm .
string Soundex(string input)
{
List<string> groups = new List<string>()
{ "aeiouy", "bfpv", "cgjkqsxz", "dt", "l", "mn", "r" };
string first = input.Substring(0, 1);
string s = input.ToLower();
s = s.Replace("h", "").Replace("w", "");
for (int g = 1; g < groups.Count; g++)
for (int i = 0; i < groups[g].Length; i++)
s = s.Replace(groups[g][i], ((char)(g + (byte)'0')));
for (int i = 1; i < 10; i++) s = s.Replace(i + "" + i, i + "");
for (int i = 0; i < groups[0].Length; i++) s = s.Replace(groups[0][i].ToString(), "");
if ( (s[0] >= '0') && (s[0] <= '9') ) s = s.Substring(1);
return (first + s.Substring(0, Math.Min(3, s.Length))).PadRight(4, '0');
}
source
share