On 22 Dec 2011, at 15:54, Alexander Reichstadt wrote:

> Thanks, but I  have not tried. My thinking went along the lines of if I read 
> the string directly from the URL I have no control over what encoding is 
> being used for reading or it defaults to something. If I first read as data, 
> I can do with those bytes as I please. The DBF file is not in one consistent 
> encoding from start to finish. The DBF file format documentation says the 
> header is in binary, then there is a linefeed (\r), then there is the body. 
> Each field has a fixed length, wether used or not doesn't matter, the unused 
> rest is filled with spaces.
> 
> So, I read the file as data, stringily it as DOSLatin1, split it at the 
> linefeed and read the body according to the field definitions I am given. 
> They are guaranteed, so maybe some day I get around to writing a nice DBF 
> parser, but until then I go by the guaranteed field lengths.

If your first step after reading the data is create a string from it, then you 
might as well use NSString directly. -[NSString 
initWithContentsOfURL:encoding:error:] does exactly what you are doing right 
now, and potentially more memory-efficiently.

That said, either of these may not be great since it's possible something in 
the binary header might cause NSString to fail. Instead you should really do:

1. Read the data into memory
2. Locate where the text begins
3. Split out a new data object containing just the text data
4. Create a string from that data_______________________________________________

Cocoa-dev mailing list ([email protected])

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/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to