读取文本文件并获取iPhone Objective-C组件

发布于 2024-10-14 02:06:32 字数 476 浏览 4 评论 0原文

我有一个当前看起来像这样的文本文件:

<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>

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

I have a text file that currently looks like this:

<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>

I just wanted to know how I can get the text inbetween the <joke> and the </joke> parts and then put them into an array.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○闲身 2024-10-21 02:06:32
 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>"];
 }
 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>"];
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文