Re: What encoding to use to turn NSData from a subprocess into an NSString?
Re: What encoding to use to turn NSData from a subprocess into an NSString?
- Subject: Re: What encoding to use to turn NSData from a subprocess into an NSString?
- From: "Michael Ash" <email@hidden>
- Date: Wed, 24 May 2006 12:01:14 -0400
On 5/24/06, Gerben Wierda <email@hidden> wrote:
What I need is an encoding that allways works on all 8bit data thrown
at it and that since the data is text output from various unix
commands is most likely to give readable results. It may not fail and
produce a nil NSString when this is handed the data with
initWithData:encoding. The issue is that I cannot predict the coding
other than it is output generated on stderr/stdout from any unix-
level tool, meant to produce readable output, which may include 8-bit
characters.
Assuming this is just for display, I recommend a two-phase approach.
Try to read the data with UTF-8 first. If it works, you're set. If it
doesn't work, then use an encoding which can never fail, such as
Latin-1, and put a note next to it in your GUI to inform the user that
it's invalid UTF-8.
If it's not for display, you should just keep the data stored in an
NSData. Storing arbitrary 8-bit data in an NSString is wrong and makes
your life difficult.
Mike
_______________________________________________
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