1. //有字符串“A~B^C_D>E",拆分出单个字母:
NSString *str =@" A~B^C_D>E ";
str = [str stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]];//去掉前边和后边的空格
NSCharacterSet * charSet = [NSCharacterSetcharacterSetWithCharactersInString:@"^~_>"];
NSArray *arr = [strcomponentsSeparatedByCharactersInSet:charSet];
//输出看效果
[arr enumerateObjectsUsingBlock:^(id obj,NSUInteger idx,BOOL *stop) {
NSLog(@"A~B^C_D->[%@]", obj);
}];
2.//关于invertedSet
NSString *string =@" 123,45_6 7/8>9a ";
NSString * kNumber =@"0123456789.";
//NSCharacterSet *numberSet = [NSCharacterSet characterSetWithCharactersInString:kNumber];
NSCharacterSet *numberSet = [[NSCharacterSetcharacterSetWithCharactersInString:kNumber]invertedSet];
//invertedSet方法是去反字符,把所有的除了kNumber里的字符都找出来(包含去空格功能)
NSString *fieldString = [[stringcomponentsSeparatedByCharactersInSet:numberSet]componentsJoinedByString:@""];
NSLog(@"number__[%@]", fieldString);