Re: Read lines from very large text file
Re: Read lines from very large text file
- Subject: Re: Read lines from very large text file
- From: Steve Sisak <email@hidden>
- Date: Sat, 7 Feb 2009 13:27:42 -0500
At 9:46 AM -0800 2/7/09, Joar Wingfors wrote:
On Feb 7, 2009, at 6:55 AM, Steve Sisak wrote:
Umm, unless I'm totally missing something, what's wrong with
fopen() and fgets(), possibly followed with [NSString
stringWithCString] on each line?
What's wrong is that they won't allow you to specify the text
encoding to use. The same thing is true for the *deprecated* method
"+stringWithCString:" by the way.
The OP specified he was working with ASCII logfiles before the
conversation went off into the weeds on text encodings:
At 8:46 PM +1100 2/3/09, Jacob Rhoden wrote:
Exactly, I was looking for direction on the technically best way to
read a very large file line by line. In future I will be sure to
include a concrete example. (:
It is not uncommon that I might have to deal with server logs that
go into the gigabytes. Most logs (apache, squid, etc...) are all
ascii encoded. The line ending is irrelevant, see a \n or a \r and
we know we have reached the end of a "entry" in the log.
Also, there are other initializers that will let you specify
encodings, for instance:
- initWithBytes:(const void *)bytes length:(NSUInteger)len
encoding:(NSStringEncoding)encoding;
you'll just need to do strlen() and check if that last character is
\n and append another fgets() if it isn't.
I was trying to answer the OP's question (how to read an ASCII file
line-by-line) in a simple manner, rather than the meta-discussion on
character encodings.
Better?
-Steve
_______________________________________________
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