Search code examples
xcodeswiftmacossoundex

Soundex returns 0 for every character


I have this function which converts a word to a soundex value, but it is returning all letters as 0. My last name, Smith, should by S530, but returns S000, for example.

Link for code (since it's too long to put on here): http://pastebin.com/9hESxV7P

I had it log the value of letterArray and it does evaluate to an array of all the letters in my last name. It has to be something in the for ... in loop. Any help would be great. Thanks!


Solution

  • changing this line

    let trimmedWord = word.uppercaseString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
    

    it produce S530