Re: From text file to NSString...
Re: From text file to NSString...
- Subject: Re: From text file to NSString...
- From: Ondra Cada <email@hidden>
- Date: Thu, 4 Jul 2002 22:38:09 +0200
On Thursday, July 4, 2002, at 10:20 , Greg Titus wrote:
file = [[NSString alloc] initWithContentsOfFile:myFileName];
lines = [file componentsSeparatedByString:@"\n"];
particularLine = [lines objectAtIndex:lineNumber];
[file release];
Notice though, that this solution reads the whole file, cuts it all up
into separate strings for each line, and then takes the one line you are
interested in. So this is not efficient if the file you are dealing with
is large.
Also, it might cause a leak if eg. lineNumber raises. The proper way to
write this is
[[[NSString stringWithContentsOfFile:myFileName]
componentsSeparatedByString:@"\n"] objectAtIndex:lineNumber];
(not speaking of the potential problem with encodings, which I've
mentioned before).
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.