How to strip special characters out of string?
问题 I have a set with the characters I allow in my string: var characterSet:NSCharacterSet = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ") I want to strip any other characters from a string so two unformatted data can be considered equal, like this: "American Samoa".lowercaseString == "american_samoa1".lowercaseString the lowercase version of these transformed strings would be "americansamoa" 回答1: Let's write a function for that (in swift 1.2). func