【小技巧】【源码】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);
}

posted @ 2018-02-26 18:31  王彬iOS  阅读(2202)  评论(0编辑  收藏  举报