该算法设置为在第一个单词上运行或直到它填充四个编码字符串。例如,输入“Horrible Great”的结果是:H612。它忽略了第二个单词,或者换句话说,它只需要第二个单词的第一个字母来填充编码的字符串。
我想通过取第一个单词并找到它的编码字符串来改变它,然后取第二个单词并找到它的编码字符串;输出应该是“H614 G600”。我想知道是否有办法通过对 **this code进行一些更改来做到这一点。
非常感谢 :)
private string Soundex(string data)
{
StringBuilder result = new StringBuilder();
if (data != null && data.Length > 0)
{
string previousCode = "", currentCode = "", currentLetter = "";
result.Append(data.Substring(0, 1));
for (int i = 1; i < data.Length; i++)
{
currentLetter = data.Substring(i,1).ToLower();
currentCode = "";
if ("bfpv".IndexOf(currentLetter) > -1)
currentCode = "1";
else if ("cgjkqsxz".IndexOf(currentLetter) > -1)
currentCode = "2";
else if ("dt".IndexOf(currentLetter) > -1)
currentCode = "3";
else if (currentLetter == "l")
currentCode = "4";
else if ("mn".IndexOf(currentLetter) > -1)
currentCode = "5";
else if (currentLetter == "r")
currentCode = "6";
if (currentCode != previousCode)
result.Append(currentCode);
if (result.Length == 4) break;
if (currentCode != "")
previousCode = currentCode;
}
}
if (result.Length < 4)
result.Append(new String('0', 4 - result.Length));
return result.ToString().ToUpper();
}