how to store the value of first line of text file through code for iphone
Asked
Active
Viewed 74 times
2 Answers
2
Try this:
NSString *fileContents = [NSString stringWithContentsOfFile:@"myfile.txt"];
NSArray *lines = [fileContents componentsSeparatedByString:@"\n"];
Aman Aggarwal
- 3,764
- 1
- 18
- 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
-
1In 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,276
- 13
- 48
- 83