let res = String(str.characters.filter { $0 != " " }) //去除空格
//过滤特殊符号
NSString *str2 = [passwdInput.text stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]]; NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"@/:;()¥「」"、[]{}#%-*+=_\\|~<>$€^•'@#$%^&*()_+'\""];原文链接:https://www.f2er.com/swift/322568.html