2013-06-01 25 views
11

区切り文字列を配列に分割しようとすると少し問題があります。基本的には、MECARDのQRコードから結果を渡し、addressBookに新しいエントリを追加したいと思います。ここで 区切り文字列をNSArrayに分割する方法

は(唯一の "姓" フィールドのために)私のコードです::「MECARD:N:

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 QRコードはよく、すべてのURL(としてのViewControllerが表示されます&をデコード...しかし、されている名前。 ORG:会社; TEL:89878978; ...など)は、私のMECARDのURL &は、右欄の右のデータを送信分離するために行方不明です何

...最初のフィールド(FistNameフィールド)に行く

答えて

25

希望?助けてください

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

あなたのヒントをお寄せいただきありがとうございます。私のコードスニペットを読んでみると、「NSArray * n = [_n componentsSeparatedByString:@ ";"]; "、MECARDではデータが" ; "ではなく、"、 "ではありません。とにかく、 ";" "、"はもう動作しません... – iNico3D

+0

あなたが見逃した例では "n" - それは[_ componentsSeparatedByString:@ ";"];多分[_n ...でなければならないでしょうか? – BlueConga

+0

右:サンプルが修正されました: "NSArray * n = [_n componentsSeparatedByString:@"; "];"しかし、私の分割された問題はまだ生きている... :-( – iNico3D

関連する問題