Re: reading several lines
Re: reading several lines
- Subject: Re: reading several lines
- From: H M <email@hidden>
- Date: Thu, 11 Oct 2007 22:38:05 +0100
On 11. Oct 2007, at 22:24, Hans van der Meer wrote:
I need to read a file containing lines of text. Like this:
abcd
efg
xyz
After some searching of the docs I came up with:
NSString *contents =
[NSString stringWithContentsOfFile: file encoding:
NSASCIIStringEncoding error: NULL];
try leaving the encoding part out. I have the following code in one
of my projects:
// set path to file
NSString *data = [NSString stringWithContentsOfFile:path];
that reads the entire file into an NSString. then I split it into
lines with
NSArray *array = [data componentsSeparatedByString:@"\n"];
--
GPG Key ID: 92AD877F7E4E32B9
Fingerprint: 16B0 7DCD 3AB0 0C45 F5FD 581D 92AD 877F 7E4E 32B9
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden