• 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: 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


  • Follow-Ups:
    • Re: reading several lines
      • From: Douglas Davidson <email@hidden>
References: 
 >reading several lines (From: Hans van der Meer <email@hidden>)

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