使用ABMultiValueCopyValueAtIndex时,如何删除所有特殊字符的NSString?

N. *_*jay 2 objective-c abaddressbook ios ios7 xcode5

当我使用ABpeoplePickerNavigationController时,当调用下面的委托时,我试图执行以下操作:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

我得到的变量号是.925.3248930,在控制台中它添加了某种".".在空白的位置.我尝试修剪空白仍然是我这样做非常不成功.伙计们,你能帮助我吗?难道我做错了什么?

Azi*_*lah 7

你可以试试

number = [number stringByReplacingOccurrencesOfString:@"." withString:@""];
Run Code Online (Sandbox Code Playgroud)

从结果字符串中删除点.

或者如果有任何其他特殊字符的可能性使用下面的代码

NSCharacterSet *onlyAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];
number = [[number componentsSeparatedByCharactersInSet:onlyAllowedChars] componentsJoinedByString:@""];
Run Code Online (Sandbox Code Playgroud)