Dear all,
Is there any function in Vb.net (or C#) that encodes a string in UCS2?
Thanks
Dear all,
Is there any function in Vb.net (or C#) that encodes a string in UCS2?
Thanks
See Encoding.Unicode
.
Given a .NET String
, call Encoding.GetBytes
to get a byte array representing that string encoded in UCS2.
Edit: In the context of System.Text.Encoding
, Unicode = UTF-16. As Johannes points out, these are not the same thing in the presence of surrogates.
No, .NET supports the full Unicode range for strings and many encodings that derive from System.Text.Encoding. You can trivially get UTF-16, but not UCS-2. However, if you first get rid of all surrogate pairs in the input string, then UTF-16 is UCS-2. But there's no built-in encoding that does that for you.