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

Caveat: I just typed it up.

HTH,
Joel





_______________________________________________

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)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us

This email sent to maillists@xxxxxxxxx

...



Privacy