【发布时间】:2012-08-31 00:37:12
【问题描述】:
我有一个包含多个单词的文本文件。它们都由新行分隔。
我尝试了什么:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"txt"];
if (filePath) { // This does trigger, so the file is actually found.
NSArray *arr = [filePath componentsSeparatedByString:@"\n"];
}
我也尝试过:
NSMutableArray * lines = [[NSMutableArray alloc] initWithArray:[filePath componentsSeparatedByString:@"\n"] copyItems: YES];
这些似乎都不起作用,因为我似乎只在使用 NSLog 读出行时才获得文件路径。有谁能帮忙吗?
lines 数组似乎只包含一个对象,即文本文件位置的字符串。
我想要一个数组,其中每个字符串都是由纺织品中的一条线分隔的字符串。
【问题讨论】:
标签: objective-c ios cocoa-touch