Assistance with removing characters from string

Discussion in 'iOS Programming' started by Pyro2b, Apr 15, 2009.

  1. Pyro2b macrumors newbie

    Aug 2, 2004
    Hi, I am new at this, and have been struggling through app development. I have a problem with some of my code. The user can choose a person's phone number in my app, and the phone number is inserted into a field. I need the phone number to be inserted into the field with no formatting. Basically like: 2123453423 instead of how is is currently being inserted like: (212) 345-3423. If anyone has suggestions as to how I can get my code to work, I'd be very appreciative. Here is what I have so far:

    - (IBAction) adressBook: (id) sender; {
    	ABPeoplePickerNavigationController *pp = [[ABPeoplePickerNavigationController alloc] init];
    	pp.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]];
    	pp.peoplePickerDelegate = self;
    	[self presentModalViewController:pp animated:YES];
    	[pp release];
    - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
        // assigning control back to the main controller
    	[self dismissModalViewControllerAnimated:YES];
    - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    	return YES;
    - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
    	ABMultiValueRef phoneProperty = ABRecordCopyValue(person,property);
    	NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phoneProperty,identifier);
    	 [[[[phone stringByReplacingOccurrencesOfString:@"(" withString:@""]
    				  stringByReplacingOccurrencesOfString:@")" withString:@""]
    				 stringByReplacingOccurrencesOfString:@"-" withString:@""]
    				stringByReplacingOccurrencesOfString:@" " withString:@""];
    	phonenumber.text = phone;
    	[phone release];
    	[self dismissModalViewControllerAnimated:YES];
    	return NO;

Share This Page