开发者

Convert UTF8 string to UTF-16 in .net

开发者 https://www.devze.com 2023-03-05 06:23 出处:网络
I have a string fromUTF开发者_高级运维8 and want to convert that to Unicode (UTF16). Please help.If you have a file and you know that encoding of the file is UTF8 you can use StreamReader to read the

I have a string from UTF开发者_高级运维8 and want to convert that to Unicode (UTF16). Please help.


If you have a file and you know that encoding of the file is UTF8 you can use StreamReader to read the file as if it is encoded in UTF8.
Regarding conversion from UTF8 to Unicode, you are comparing 2 different things. Check the link in my comment to your question.
System.Text.UTF8Encoding is UTF8 System.Text.UnicodeEncoding is UTF16. Check this link for conversion. You would be using Encoding.Convert()


Use System.Text.Encoding.UTF8.GetString().

Pass in your UTF-8 encoded text, as a byte array. The function returns a standard .net string which is encoded in UTF-16.

0

精彩评论

暂无评论...
验证码 换一张
取 消