Re: Opening old text files with non-deprecated stringWithContentsOfFile calls?
Michael Dupuis <smokinmonkey-/[email protected]> Thu, 14 Oct 2010 10:12:32 -0700 (PDT)
| Newsgroups | gmane.comp.macosx.devel |
|---|---|
| Message-ID | <[email protected]> |
Just to update, so, it looks like in general, if you don't know what the encoding of the file will be, you can TRY to use the usedEncoding call, and that might figure out the encoding for you, but it appears to only try a limited set of possible encodings (maybe only the UTF and Unicode encodings). What I finally decided to do was make my own stringWithContentsOfFile that basically tries to open a file with each encoding, one at a time, upon failure, in the order that is most likely to be correct, until one is found. Brute force. Maybe that's not the right way to do it, but it seems to work, maybe that's what the deprecated call was doing, I'm not sure. Unfortunately, forcing the user to pick an encoding for a text file that they have downloaded from the web just isn't going to be practical in most cases, most people will have no idea what an encoding even is. Soooo, at least going through the opens should succeed once the tired encoding results in a string rather than an error. Michael