Protocole
Protocole

Reputation: 1743

Objective-C: How can I decode a unicode character back to a string?

I encode a string using NSUTF32BigEndianStringEncoding like this:

NSString *utf32BigEndianString = [[NSString alloc] initWithFormat:@"%@", [text dataUsingEncoding:NSUTF32BigEndianStringEncoding]];

For example, this would give me the unicode <00000041> for the string A. So how can I got the string A back from the unicode <00000041>. Thank you very much.

Upvotes: 0

Views: 929

Answers (1)

Frederick Cheung
Frederick Cheung

Reputation: 84114

What you have there isn't actually a utf32 big endian string - what you have is a string containing a programmer friendly display of an NSData containing some utf32 big endian data

You can get from an NSData to a NSString using NSString's initWithData:encoding: method.

If you absolutely had to use that string you have there you'd probably need to first turn it back into an NSData.

Upvotes: 2

Related Questions