Ios 使用ABMultiValueCopyValueAtIndex时,如何在删除所有特殊字符的情况下获取NSString?
当我使用ABpeoplePickerNavigationController时,当调用下面的委托时, 我正在努力做到以下几点:Ios 使用ABMultiValueCopyValueAtIndex时,如何在删除所有特殊字符的情况下获取NSString?,ios,objective-c,ios7,xcode5,abaddressbook,Ios,Objective C,Ios7,Xcode5,Abaddressbook,当我使用ABpeoplePickerNavigationController时,当调用下面的委托时, 我正在努力做到以下几点: - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identif
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
if(property == kABPersonPhoneProperty || property == kABPersonEmailProperty)
{
NSString *name = (__bridge NSString *)ABRecordCopyCompositeName(person);
ABMutableMultiValueRef multi = (ABMultiValueRef)ABRecordCopyValue(person, property);
NSString *number = (__bridge NSString*)ABMultiValueCopyValueAtIndex(multi, identifier);
if(![VZMUtils validateEmail:number])
number = [VZMUtils formatIdentificationNumber:number];
number = [number stringByReplacingOccurrencesOfString:@"." withString:@""];
ALog(@"number %@ and name %@",number,name);
[self.popoverDelegate setDataWithName:name andDetail:number];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid type selected." message:@"Please select either a phone number or email address to add as a recipient" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
[self dismissViewControllerAnimated:YES completion:nil];
return NO;
}
我得到的可变数字是.925.3248930,在控制台中,它在空白处添加了某种“.”。我尝试过删减空白,但我还是没有成功。伙计们,你们能帮我吗?我做错什么了吗?你可以试试
number = [number stringByReplacingOccurrencesOfString:@"." withString:@""];
从结果字符串中删除点
或者,如果有任何其他特殊字符的可能性,请使用下面的代码
NSCharacterSet *onlyAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];
number = [[number componentsSeparatedByCharactersInSet:onlyAllowedChars] componentsJoinedByString:@""];
我也试过了,但没用。通常,如果您键入一个句号“”,它会被置于行的底部。我觉得它的特殊性质,它的添加看起来像一个完全停止,但被放置在中间的线。我不知道这是什么样的特殊性格。在控制台中,它以这种方式显示,但在调试时,当我将光标放在变量上时,它会显示一个空白。怪异行为。@N.AnantVijay,如果有帮助,你可以接受答案。