parsingRTF文件到NSArray – 目标C

我试图从RTF文件parsing和英语词典到一个数组。

我本来有工作,但我不知道为什么现在不是。

在字典中,每个单词由一个新行(\ n)分隔。 我的代码到目前为止是:

//loading the dictionary into the file and pull the content from the file into memory NSData *data = [NSData dataWithContentsOfFile:@"wordList.rtf"]; //convert the bytes from the file into a string NSString *string = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding]; //split the string around newline characters to create an array NSArray *englishDictionary = [string componentsSeparatedByString:@"\n"]; 

当我尝试和NSLog它,它只是(空)…

我已经看过: Objective-C:逐行读取文件

但是尹莉没有得到答案正确的工作。 它在最后打印出两个反斜杠,以及在开始时的许多不必要的东西!

任何帮助将不胜感激! 干杯!

尝试使用纯文本(txt)文件而不是rtf。 RTF文件也包含关于文本的格式化信息。 这就是你阅读内容后看到的不必要的东西。