【问题标题】: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>

我只是想知道如何获取&lt;joke&gt;&lt;/joke&gt; 部分之间的文本,然后将它们放入一个数组中。

【问题讨论】:

    标签: 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>"];
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多