Re: initWithContentsOfFile:usedEncoding:error: Not working?
Re: initWithContentsOfFile:usedEncoding:error: Not working?
- Subject: Re: initWithContentsOfFile:usedEncoding:error: Not working?
- From: Ondra Cada <email@hidden>
- Date: Tue, 11 Apr 2006 15:18:21 +0200
Larry,
On 11.4.2006, at 9:05, Larry Fransson wrote:
I'm trying to initialize a string using NSString -
initWithContentsOfFile:usedEncoding:error:. I'm getting an error
(#261) that says the file can't be opened using the specified text
encoding. This happens whether I specify an encoding or not.
According to the docs, this method is supposed to try to determine
the encoding used and return it by reference.
It does try, but alas it is not particularly good trying. IIRC, it
would correctly recognize UTF-16 and -32 if they have their prefixes,
and that's about all (perhaps plain ASCII, too :))
If you need to determine the encoding from the data, it's best to DIY
at any level you need (from just trying which encoding can interpret
the data through a frequency analysis of characters to a full-blown
analysis which may include spellchecking the text in the target
language -- if known -- and selecting the encoding which yields the
least number of misspelled words).
Whatever you do though, don't forget to allow the user to override
the encoding, for just *any* heuristic is bound to fail sometimes.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden