Skip navigation.
 
mlRe: How to convert UInt8 array to NSString
FROM : Joe Goh
DATE : Thu May 08 21:26:01 2008

Hi Marc,

Wish this thread existed 2 years ago.  :-)  But I digress..

You may also consider using the alternative approach of getting the
user to select the most readable encoding (after you've tried
automatically detecting it) and floating the most appropriate/most
frequently used encodings on top.

A screenshot of that approach in action in my app:
http://funkeemonk.cachefly.net/international.png

Good luck!
Joe Goh
FunkeeMonk Technology
http://www.funkeemonk.com/

On 5/9/08, "Gary L. Wade" <<email_removed>> wrote:
>  Sorry, I misread your suggested method, but, as Adam points out, it still isn't
> adequate for someone who has free-styled 8-bit text with no idea what the original
> encoding was.
>
>  >
>  >On Wednesday, May 07, 2008, at 12:37PM, "Jean-Daniel Dupas"
>  ><<email_removed>> wrote:
>  >>What make you think this function assumes an exact encoding ? This
>  >>method is not the same than +[NSString
>  >>stringWithContentsOfFile:encoding:error:].
>  >>
>  >>The method +stringWithContentsOfFile:usedEncoding:error: returns the
>  >>sniffed encoding by reference using the second argument. At least
>  >>that's what the documentation says: “ This method attempts to
>  >>determine the encoding of the file at path.â€
>  >>This method was introduced in Tiger, that's maybe why you never see it
>  >>before.
>  >
>  >Unfortunately, that method doesn't work unless you have UTF-16 or UTF-32 with
>  >a BOM on Tiger, which makes it less useful than it might be.  On Leopard it
>  >reads xattrs, then tries UTF-8 if it's not UTF-16/32, but it certainly doesn't
>  >sniff encodings like TEC.  I was never motivated enough to figure out TEC, so
>  >basically ended up checking for BOM, trying UTF-8, and then using MacRoman if
>  >all else failed.
>  >
>  >--
>  >adam

Related mailsAuthorDate
mlHow to convert UInt8 array to NSString Marc Lohse May 5, 14:17
mlRe: How to convert UInt8 array to NSString Hank Heijink (Mail… May 5, 14:56
mlRe: How to convert UInt8 array to NSString Jens Alfke May 5, 18:20
mlRe: How to convert UInt8 array to NSString Thomas Engelmeier May 6, 16:03
mlRe: How to convert UInt8 array to NSString Jens Alfke May 6, 17:56
mlRe: How to convert UInt8 array to NSString Aki Inoue May 6, 19:45
mlRe: How to convert UInt8 array to NSString Clark Cox May 6, 19:56
mlRe: How to convert UInt8 array to NSString Ricky Sharp May 7, 00:37
mlRe: How to convert UInt8 array to NSString Jens Alfke May 7, 04:22
mlRe: How to convert UInt8 array to NSString Ricky Sharp May 7, 04:53
mlRe: How to convert UInt8 array to NSString Gary L. Wade May 7, 19:33
mlRe: How to convert UInt8 array to NSString Jean-Daniel Dupas May 7, 20:54
mlRe: How to convert UInt8 array to NSString Gary L. Wade May 7, 21:27
mlRe: How to convert UInt8 array to NSString Jean-Daniel Dupas May 7, 21:36
mlRe: How to convert UInt8 array to NSString Adam R. Maxwell May 7, 22:14
mlRe: How to convert UInt8 array to NSString Gary L. Wade May 8, 20:07
mlRe: How to convert UInt8 array to NSString Joe Goh May 8, 21:26