如何将分隔的NSString拆分为NSArray

时间:2013-06-01 15:11:03

标签: ios nsstring nsarray addressbook

当我尝试将分隔的字符串拆分为数组时,我遇到了一些问题。基本上,我想从MECARD QRCode传递结果并向addressBook添加新条目。

这是我的代码(仅适用于“FirstName”字段)::

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解码良好& viewController出现...但是所有的URL(如:“MECARD:N:name; ORG:company; TEL:89878978; ......等等)都进入第一个字段(FistName字段)......

将我的MECARD URL和&在正确的字段中发送正确的数据?

1 个答案:

答案 0 :(得分:25)

希望有所帮助

NSArray *chunks = [string componentsSeparatedByString: @";"];