Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从数组中逐行读取文本文件_Objective C - Fatal编程技术网

Objective c 从数组中逐行读取文本文件

Objective c 从数组中逐行读取文本文件,objective-c,Objective C,我有一个文本文件,我想在一个特定的列中搜索带有数组的值 让我解释一下,假设我的文件名为:Data.txt 它包括: Row_sign:Hello1 Row_sign:Hello2 Row_sign:Hello3 我想读取文件并返回数组 并按如下方式输出阵列: NSLog(@"%@ %@ %@", array[0], array[1], array[2]); 问题是我不知道怎么做。有人能告诉我如何一步一步地从中学习吗 // Get your file NSString *file = [[NS

我有一个文本文件,我想在一个特定的列中搜索带有数组的值

让我解释一下,假设我的文件名为:Data.txt

它包括:

Row_sign:Hello1
Row_sign:Hello2
Row_sign:Hello3
我想读取文件并返回数组

并按如下方式输出阵列:

NSLog(@"%@ %@ %@", array[0], array[1], array[2]);
问题是我不知道怎么做。有人能告诉我如何一步一步地从中学习吗

// Get your file
NSString *file = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"txt"];
// Read its contents
NSString *fileContents = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil];
// Each new line is a new item in our array
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
NSLog([lines objectAtIndex:0]); // Row_sign:Hello1
NSLog([[lines objectAtIndex:0] componentsSeparatedByString:@":"]); // Hello1

有关更多信息,请参阅这些Apple文档:,。

您知道如何将txt文件作为字符串读取吗?你知道如何将一个字符串分割成一个数组吗?目标我不清楚。数组[0]实际上应该是什么?我完全不知道,但是数组[0]应该返回=Hello1Perfect!但是如果不是包含信息的文件,而是nsstring呢??相反,您可以向meMatt i agree显示行号:most not remainit表示警告:格式字符串不是字符串文字(可能不安全)