• 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 one line at a time using NSFileHandle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading one line at a time using NSFileHandle


  • Subject: Re: Reading one line at a time using NSFileHandle
  • From: Michael Ash <email@hidden>
  • Date: Thu, 26 Mar 2009 18:50:46 -0400

On Thu, Mar 26, 2009 at 5:48 PM, Erg Consultant
<email@hidden> wrote:
> Tried that approach too. Problem with using NSString is that when it comes time to write the line out to the new file, I need an NSData and to create one, I have to use NSString's getBytes or getCharacters. Those only return unicode arrays, which, when I go to write to a text file gives me a '?' between each character. My original file is encoded in MacRoman. There is no way to specify the encoing for the lines being written out.
>
> It is absolutely mind-boggling that Apple does not provide a simple, easy API for doing this.

What makes you think they don't?

1) Read a file into an NSString: 1 line of code
2) Split an NSString into lines: 1 line of code
3) Process each line and produce a new one: about 2 lines of code for
the overhead, the processing itself is obviously up to you
4) Combine the lines back into an NSString: 1 line of code
5) Write the combined NSString to a file: 1 line of code

Excluding the application-specific stuff, we're talking about six
lines of code. That definitely qualifies as simple and easy in my
book.

This technique won't work for really huge files, because it loads the
entire thing into memory. But at under one kilobyte, your file is many
orders of magnitude away from that limit, so it doesn't matter.

Mike
_______________________________________________

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: 
 >Re: Reading one line at a time using NSFileHandle (From: Matt Neuburg <email@hidden>)
 >Re: Reading one line at a time using NSFileHandle (From: Erg Consultant <email@hidden>)
 >Re: Reading one line at a time using NSFileHandle (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Reading one line at a time using NSFileHandle (From: Erg Consultant <email@hidden>)

  • Prev by Date: Re: [Q] Strange Drag & Drop from my app to FCP project window
  • Next by Date: Advice on the suitability of Core Animation in this situation
  • Previous by thread: Re: Reading one line at a time using NSFileHandle
  • Next by thread: Re: Reading one line at a time using NSFileHandle
  • Index(es):
    • Date
    • Thread