This algorithm is configured to execute on the first word or until it fills in four encoded lines. For example, the result of typing "Horrible Great" is: H612. He neglects the second word, or, in other words, only the first letter of the second word is required to fill in the encoded string.
I would like to change it by taking the first word and finding its encoded string, and THEN take the second word and find its encoded string; The output should be "H614 G600". Please, I would like to know if there is a way to do this by making some changes to ** this code.
Thank you very much.
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(); }
user979014
source share