-1

how to store the value of first line of text file through code for iphone

rajiv
  • 1

2 Answers2

2

Try this:

NSString *fileContents = [NSString stringWithContentsOfFile:@"myfile.txt"];
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
Aman Aggarwal
  • 3,754
  • 1
  • 19
  • 26
  • sorry this one is not valid for me i want to store the first line of text value in nsstring and want to print that in lable.text – rajiv May 03 '11 at 06:36
  • 1
    In that case you can retrieve the string with : NSString *text = [lines objectAtIndex:0]; – Hugo Briand May 03 '11 at 07:26
0

Adam Rosenfield answered your question here: Reading a file line by line

Community
  • 1
  • 1
Ahmad Kayyali
  • 8,233
  • 13
  • 49
  • 83