// 拷贝手机号码去除多余字符 iOS 11的通讯录号码复制问题
+ (NSString *)getSeparatedPhoneNumberWithString:(NSString *)phoneString {
// 去除+86
if ([phoneString containsString:@"+86"]) {
phoneString = [phoneString stringByReplacingOccurrencesOfString:@"+86" withString:@""];
}
NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
NSString * string = phoneString;
//invertedSet方法是去反字符,把所有的除了characterSet里的字符都找出来(包含去空格功能)
NSCharacterSet *specCharacterSet = [characterSet invertedSet];
NSArray * strArr = [string componentsSeparatedByCharactersInSet:specCharacterSet];
return [strArr componentsJoinedByString:@""];
}
网友评论