Re: reading several lines
Re: reading several lines
- Subject: Re: reading several lines
- From: Douglas Davidson <email@hidden>
- Date: Thu, 11 Oct 2007 14:50:28 -0700
On Oct 11, 2007, at 2:38 PM, H M wrote:
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"];
Please don't leave the encoding out. If you're going to use plain
text files, you need to know what encoding you are using. (If you
need a suggestion, I recommend UTF-8.)
If you know what line terminator your file uses,
componentsSeparatedByString: is OK, although it may not be the most
efficient solution for all purposes. If you don't know what line
terminator your file might be using, use methods like
lineRangeForRange: or getLineStart:end:contentsEnd:forRange:.
Douglas Davidson
_______________________________________________
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