• 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: Joel Norvell <email@hidden>
  • Date: Wed, 25 Mar 2009 20:38:02 -0700 (PDT)

> Is there a way to read one line of a text file at a time
> using NSFileHandle (the way fgets does)?

This code illustrates how you might approach
filtering lines of data obtained through an NSFileHandle.

    NSFileHandle* yourFileHandle;
    NSString*     input;
    NSArray*      lines;
    int           i;

    input = [[NSString alloc] initWithData: [yourFileHandle availableData]
                                  encoding: NSUTF8StringEncoding];
    [input autorelease];

    lines = [input componentsSeparatedByString: @"\n"];

    for (i = 0; i < [lines count]; i++)
    {
        if ([[lines objectAtIndex:i] hasPrefix: @"Oh Noes!"])
        {
            result = YES;
            break;
        }
    }

Caveat: I just typed it up.

HTH,
Joel





_______________________________________________

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: "Jeff Laing" <email@hidden>
  • Prev by Date: Re: GetProcessBundleLocation() -- no good in background agents!
  • Next by Date: RE: Reading one line at a time using NSFileHandle
  • Previous by thread: Reading one line at a time using NSFileHandle
  • Next by thread: RE: Reading one line at a time using NSFileHandle
  • Index(es):
    • Date
    • Thread