Re: Reading one line at a time using NSFileHandle
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