不知道是不是系統(tǒng)有問(wèn)題,在通訊錄復(fù)制的電話號(hào)碼粘貼出來(lái)是15位,通過(guò)去掉字符串空格的辦法處理之后,還是13位,明明看不到空格了,但長(zhǎng)度還是13位。
下面是解決辦法,希望能幫助到你:
//結(jié)束編輯
-(void)textViewDidEndEditing:(UITextView *)textView
{
// 去掉數(shù)字
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);
}