Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is .Net Unicode Encoding's equivalent in Objective-C?

What is the equivalent in Objective-C of .Net's System.Text.Encoding.Unicode? I have tried:

  • NSUnicodeStringEncoding
  • NSUTF8StringEncoding
  • NSUTF16StringEncoding

None of the above converted the text back correctly.

like image 411
skcrpk Avatar asked May 18 '13 13:05

skcrpk


1 Answers

According to http://msdn.microsoft.com/de-de/library/system.text.encoding.unicode.aspx, System.Text.Encoding.Unicode is the little-endian UTF-16 encoding. The equivalent NSString encoding is NSUTF16LittleEndianStringEncoding.

NSUTF16StringEncoding is almost the same, but prepends a Unicode Byte-Order Marker (BOM) FF FE to the data. (And strictly speaking, it is not documented that NSUTF16StringEncoding uses little-endian, so the explicit NSUTF16LittleEndianStringEncoding should be used anyway.)

like image 143
Martin R Avatar answered Oct 21 '22 20:10

Martin R