c# - 将 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 文本上显示“привет”
请给点建议谢谢
解决方案
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);
推荐阅读
- javascript - 防止提交错误返回 Javascript
- visual-studio-code - VS Code、Prettier 和 Flow 不能很好地协同工作——我错过了什么?
- python - How to test sequential operations in a python class involving class data
- r - 对多列进行分层以进行交叉验证
- python - 表单中的 Django 字段
- sequelize.js - Sequelize:为什么我收到未处理的拒绝 SequelizeDatabaseError:列 Receiver.receiver 不存在
- python - 为什么修改属性时会绕过设置方法?
- algorithm - 简单的数学任务:给出 2 个数字,我们必须找到第三个。我只需要一个公式
- sublimetext3 - Gosublime 不接受来自控制台的标准输入
- javascript - 将字符串一致地转换为从 0 到 100 的随机百分比