【小技巧】【源码】iOS复制电话本号码消除空格的方法
iOS11,复制电话本联系人电话时,复制的不是11位的手机号而是15位,这是系统bug,iOS如何复制电话本号码消除空格呢,直接上代码
//结束编辑
-(void)textViewDidEndEditing:(UITextView *)textView
{
// 去掉数字
NSLog(@"%lu",(unsigned long)textView.text.length);
NSMutableString *strippedString = [NSMutableString
stringWithCapacity:textView.text.length];
NSScanner *scanner = [NSScanner scannerWithString:textView.text];
NSCharacterSet *numbers = [NSCharacterSet
characterSetWithCharactersInString:@"0123456789"];
while ([scanner isAtEnd] == NO) {
NSString *buffer;
if ([scanner scanCharactersFromSet:numbers intoString:&buffer]) {
[strippedString appendString:buffer];
}
else {
[scanner setScanLocation:([scanner scanLocation] + 1)];
}
}
NSLog(@"%@", strippedString);
textView.text = strippedString;
NSLog(@"%lu",(unsigned long)textView.text.length);
}