Re: Reading one line at a time using NSFileHandle

> 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;

Caveat: I just typed it up.



Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)

Help/Unsubscribe/Update your Subscription:

This email sent to maillists@xxxxxxxxx