iOS拷贝手机号去除多余字符(iOS 11拷贝通讯录)

2018-01-27  本文已影响76人  流老湿

// 拷贝手机号码去除多余字符 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:@""];

}

上一篇下一篇

猜你喜欢

热点阅读