Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a delimited NSString into NSArray

I have a little problem when I try to split delimited string into an Array. Basically, I want to pass result from MECARD QRCode and add new entry to addressBook.

Here is my code (for "FirstName" field only) : :

NSLog(@"found CB");
NSLog(@"_code.text = %@", code.content);
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABPersonCreate();

NSString *_n = [NSString stringWithFormat:@"_code.text = %@", code.content];
NSArray *n = [_n componentsSeparatedByString:@";"];
NSLog(@"_code.text = %@",n);

ABRecordSetValue(person, kABPersonFirstNameProperty, _name, nil);

ABAddressBookAddRecord(addressBook, person, nil);
CFRelease(addressBook);

ABNewPersonViewController *c = [[ABNewPersonViewController alloc] init];
[c setNewPersonViewDelegate:self];
[c setDisplayedPerson:person];
CFRelease(person);
[self.navigationController pushViewController:c animated:YES];
[c release];

MECARD QRCode is well decoded & viewController appears... But all the URL (as : "MECARD:N:name;ORG:company;TEL:89878978; ...Etc.) goes in first field (FistName field)...

What am missing to separate my MECARD URL & send right data in right field?

like image 410
iNico3D Avatar asked Jun 01 '13 15:06

iNico3D


1 Answers

Hope it helps

NSArray *chunks = [string componentsSeparatedByString: @";"];
like image 59
BlueConga Avatar answered Oct 12 '22 14:10

BlueConga