首页 > 解决方案 > 将 UTF8 文本编码为 Unicode C#

问题描述

如何将 UTF8 文本编码为 Unicode?

string text_txt = "пÑивеÑ";    
byte[] bytesUtf8 = Encoding.Default.GetBytes(text_txt);
text_txt = Encoding.UTF8.GetString(bytesUtf8);

问题是输出:п??иве?</p>

我需要输出:привет

使用该站点:httpsUTF-8 text (Example: a 中 Я ://www.branah.com/unicode-converter 在“ )”中输入文本到“ пÑивеє,它将在 Unicode 文本上显示“привет”

请给点建议谢谢

标签: c#decodeencode

解决方案


   byte[] utf8Bytes = new byte[text_txt.Length];
                for (int i = 0; i < text_txt.Length; ++i)
                {
                    //Debug.Assert( 0 <= utf8String[i] && utf8String[i] <= 255, "the char must be in byte's range");
                    utf8Bytes[i] = (byte)text_txt[i];
                }
                text_txt= Encoding.UTF8.GetString(utf8Bytes, 0, text_txt.Length);

来自答案:如何将 UTF-8 字符串转换为 Unicode?


推荐阅读