Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: initWithContentsOfFile:usedEncoding:error: Not working?



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: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >initWithContentsOfFile:usedEncoding:error: Not working? (From: Larry Fransson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.