2

当我使用 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;
}

我得到的变量号是 .925.3248930,在控制台中它添加了某种“。” 在空格的位置。我尝试修剪空格,但我这样做非常不成功。伙计们,你能帮我解决这个问题吗?难道我做错了什么?

4

1 回答 1

7

你可以试试

number = [number stringByReplacingOccurrencesOfString:@"." withString:@""];

从结果字符串中删除点。

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

NSCharacterSet *onlyAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];
number = [[number componentsSeparatedByCharactersInSet:onlyAllowedChars] componentsJoinedByString:@""];
于 2013-09-28T07:51:07.033 回答