【问题标题】:Read text file and get components iPhone Objective-C读取文本文件并获取组件 iPhone Objective-C
【发布时间】:2011-01-24 23:57:37
【问题描述】:
我有一个当前看起来像这样的文本文件:
<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> 部分之间的文本,然后将它们放入一个数组中。
【问题讨论】:
标签:
objective-c
xcode
ios4
nsstring
text-files
【解决方案1】:
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>"];
}