• 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: Jean-Daniel Dupas <email@hidden>
  • Date: Thu, 26 Mar 2009 22:05:55 +0100

If this is a small file, just create an NSString and iterate over lines.
Here is a simple snippet that count number of lines in a string. You can modify it for your purpose.


NSString *string;
unsigned numberOfLines, index, stringLength = [string length];
for (index = 0, numberOfLines = 0; index < stringLength; numberOfLines+ +)
index = NSMaxRange([string lineRangeForRange:NSMakeRange(index, 0)]);



Le 26 mars 09 à 21:27, Erg Consultant a écrit :

I read the CocoaBuilder thread to no avail. fgets won't work in my case because my text file contains special characters which fgets mangles.

BTW, my file is not large - less than 1K. And I know it's encoding - MacRoman. And I know the line endings "/n".

But what I don't know is which API to use to read non-ASCII lines of text one at a time from one file, and write them to another file after processing each one.

One would think Cocoa would have something like fgets but that works with any encoding.

Erg




________________________________ From: Matt Neuburg <email@hidden> To: Erg Consultant <email@hidden> Cc: email@hidden Sent: Thursday, March 26, 2009 7:24:29 AM Subject: Re: Reading one line at a time using NSFileHandle

On Wed, 25 Mar 2009 19:36:01 -0700 (PDT), Erg Consultant
<email@hidden> said:
Is there a way to read one line of a text file at a time using NSFileHandle
(the way fgets does)?

Is it my imagination or did we not just have a big thread about this...?

<http://www.cocoabuilder.com/archive/message/cocoa/2009/2/2/229302>

m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



_______________________________________________

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

_______________________________________________

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 one line at a time using NSFileHandle
      • From: Erg Consultant <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>)

  • Prev by Date: Re: CoreLocation
  • Next by Date: OpenGL context sharing
  • 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