0

我为此目的使用以下代码

 ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue(ref, kABPersonPhoneProperty);
        NSString* mobile=@"";
        NSString* mobileLabel;
        for (int i=0; i < ABMultiValueGetCount(phones); i++) {
            //NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phones, i);
            //NSLog(@"%@", phone);
            mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
            if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
                NSLog(@"mobile:");
            } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel]) {
                NSLog(@"iphone:");
            } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhonePagerLabel]) {
                NSLog(@"pager:");
            }
            [mobile release];
            mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
            NSLog(@"%@", mobile);
            [_Phonearray addObject:mobile]; 
        }   

现在我的问题是_phonearray的nslog是这样的

_

Phonearray(
    "(658) 932-6593",
    "(654) 498-9878"
)

但我想喜欢

_Phonearray(
    "6589326593",
    "6544989878"
)

那么我应该在代码中做什么:?

4

1 回答 1

1

那么,您想从 ? 中删除所有非数字字符mobile?我在这里找到了一个方法:

使用 NSCharacterSet 删除所有不需要的字符 - Thinbug

NSCharacterSet* charactersToRemove = [[NSCharacterSet decimalDigitCharacterSet] invertedSet] ;
mobile = [[mobile componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString:@""] ;
于 2013-04-01T14:16:26.077 回答