• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: reading several lines
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >reading several lines (From: Hans van der Meer <email@hidden>)
 >Re: reading several lines (From: H M <email@hidden>)

  • Prev by Date: Re: documentation
  • Next by Date: Re: documentation
  • Previous by thread: Re: reading several lines
  • Next by thread: Re: documentation
  • Index(es):
    • Date
    • Thread