2011-01-24 15 views
1

を取得し、私は現在、このようになりますテキストファイルを持っている:読むテキストファイルとコンポーネントのiPhoneのObjective-C

<joke>What do you call an Italian man with one toe?</joke> 
<answer>Roberto!!</answer> 
<joke>What is the best time to go to the dentist? </joke> 
<answer>2:30 (Tooth Hurty)!!</answer> 
<joke>Why was the doctor mad?</joke> 
<answer>Because he had no patients!!</answer> 

を私はちょうど私が<joke>挟んテキストと</joke>部品を得ることができる方法を知りたいと思ったし、それらを配列に入れます。

答えて

3
NSArray *chunks = [jokertf componentsSeparatedByString:@"<joke>"]; 
for (int i = 0; i < [chunks count]; i++) { 
    NSString *c = [chunks objectAtIndex:i]; 
    NSArray *c2 = [c componentsSeparatedByString:@"</joke>"]; 

    NSArray *aChunks = [jokertf componentsSeparatedByString:@"<answer>"]; 
    NSString *a = [aChunks objectAtIndex:i]; 
    NSArray *a2 = [a componentsSeparatedByString:@"</answer>"]; 
} 
関連する問題