0

I'm fetching data from AllContacts; in that data I'm getting contact details such as (998) 989-8989. Using this number, I'm not able to make a call. Can any one help out with this? Thanks in advance.

jscs
  • 63,694
  • 13
  • 151
  • 195
siva
  • 1,402
  • 2
  • 14
  • 28

2 Answers2

1

HI All

At last i have used this following code to resolve this issue

NSString *originalString = @"(998) 989-8989";
NSMutableString *strippedString = [NSMutableString 
                                   stringWithCapacity:originalString.length];

NSScanner *scanner = [NSScanner scannerWithString:originalString];
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);

Thanks All

siva
  • 1,402
  • 2
  • 14
  • 28
0

Sounds like you can just remove spaces, brackets and hypens.

NSString *phoneNumber = @"(998) 989-8989";
phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"(" withString:@""];
phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@")" withString:@""];
phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
phoneNumber = [@"tel://" stringByAppendingString:phoneNumber];
[[UIApplication sharedApplication] openURL:phoneNumber];
Zaky German
  • 14,324
  • 4
  • 25
  • 31
  • Thanks dude ,but in different countries they will have different format of calling the phone numbers.In that way it will create a problem again :( – siva Apr 07 '11 at 09:15