Re: NSString looses Umlaute
Re: NSString looses Umlaute
- Subject: Re: NSString looses Umlaute
- From: Mike Abdullah <email@hidden>
- Date: Thu, 22 Dec 2011 17:01:19 +0000
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@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