Re: Data to String: what encoding?
Re: Data to String: what encoding?
- Subject: Re: Data to String: what encoding?
- From: Douglas Davidson <email@hidden>
- Date: Sun, 15 Sep 2002 12:38:56 -0700
On Sunday, September 15, 2002, at 12:24 PM, Randall Crenshaw wrote:
There doesn't seem to be a method like -(NSStringEncoding)
stringEncoding; on NSData. How does one deal with
arbitrary encodings? My method should be able to open any
file that can be saved on the disk. I really don't want to
worry about encodings, but if I have to then I need a way
to discover them dynamically.
It is impossible in principle to determine the encoding used for an
arbitrary file. If the file contains sufficient amounts of
natural-language text, then a human reader can usually determine the
intended encoding, but it is easy to produce files for which many
different encodings might have been used. Any method of the sort you
propose would be no more than a reasonable guess.
Take a look at what TextEdit does in this case: it allows the user to
choose what encoding to use. If no choice is made, it will attempt to
detect UTF-16 (by looking for a BOM), but otherwise will use a default
encoding.
Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.