Skip navigation.
 
mlRe: How to convert UInt8 array to NSString
FROM : Jens Alfke
DATE : Tue May 06 17:56:38 2008

On 6 May '08, at 7:03 AM, Thomas Engelmeier wrote:

> As the OP wants to create NSStrings with data created by his 
> application I'm pretty sure he will not want the the Windows 
> encoding - unless he parses text documents originating from Windows.


He didn't say where the data originates from, or what those APIs are 
that return the strings. If they're networking APIs, the data could 
very likely have originated on Windows.

Also, you missed my point about using CP1252 (WinLatin1). It's useful 
as a fallback for any unknown C strings because (a) it's a superset of 
ISO-Latin-1, which (b) has no gaps in it (as ISO does, from 
0x80-0x9F), so decoding text into an NSString will never fail and 
return nil. (I've debugged several crashes that stemmed from nil 
NSStrings decoded from garbage strings.)

> If the bytes come from MacOS text files he may want to use the 
> MacRoman encoding, otherwise creating UTF8 and passing around 
> NSStrings will be the way to go - especially in Europe where all 
> that äöüñá goodies exist.


For the most part only old (pre-OS X) files would still be using 
MacRoman. Current Mac apps generally default to UTF-8.

—Jens

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