Objective-C / iPhone - 从文本文件中读取一个单词。如果单词存在则循环

时间:2011-04-02 15:07:51

标签: iphone objective-c loops nsarray

我想在文本文件中创建显式单词列表。然后我希望能够在iPhone上读取和循环浏览此文件。最好的方法是什么?

如,

explicit.txt

hello
world
freddy
jason
foo
bar

然后在我保存信息之前,我想弹出一条消息,通知用户某个特定字是明确的。

2 个答案:

答案 0 :(得分:1)

您可能希望使用属性列表,而不是文本文件。

查看编程指南以获取大量信息。

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html%23//apple_ref/doc/uid/10000048i

答案 1 :(得分:1)

如果您的单词太多,最好使用数据库。 但如果他们只是一些话,你可以尝试这个想法:

将文字存储在explicit.txt文件中,格式如下:

  

|你好|世界|弗雷迪|杰森| FOO |酒吧|

然后加载整个文本并搜索子串|word|。 如果你找到它,那么给定的单词是明确的:

NSString *explicitWords = [NSString stringWithContentsOfFile:@"explicit.txt"];
if ([explicitWords rangeOfString:@"|word|"].location != NSNotFound) {
   // the given word is explicit.
}
相关问题