在Objective-C中,如何检查单个字符是字母还是数字?我想消除所有其他字符。

最佳答案

NSCharacterSet *validChars = [NSCharacterSet alphanumericCharacterSet];
NSCharacterSet *invalidChars = [validChars invertedSet];

NSString *targetString = [[NSString alloc] initWithString: @"..."];
NSArray *components = [targetString componentsSeparatedByCharactersInSet:invalidChars];

NSString *resultString = [components componentsJoinedByString:@""];

10-08 08:12