[C#] UTF8字符串为可读的unicode [英] [C#] UTF8 string to readable unicode

查看:147
本文介绍了[C#] UTF8字符串为可读的unicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下变量:

I have the following variable:

String test = "Çorovodë";



如何将String变量测试的内容转换为可读的unicode字符串?
我知道结果应该是Çorovodë


感谢您的帮助.



How do I convert the content of the String variable test to readable unicode string?
I know that the result should be Çorovodë


Thanks for any help

推荐答案

您永远不应该使用该格式的变量.读入时,可以指定要使用的Encoding(它是StreamReader的构造函数参数).如果要从字节流(例如套接字)构造字符串,则需要调用Tricoding提到的Encoding.GetString.
You should never have the variable in that form. When you read it in, you can specify the Encoding to use (it''s a constructor argument to StreamReader). If you''re constructing the strings from byte streams (for example sockets) then you need to call Encoding.GetString, as Trirnd mentioned.


看一下Encoding类,解决方案类似于Encoding.Unicode.GetString(Encoding.UTF8.GetBytes(utf8String))
Look at Encoding class, solution is something like Encoding.Unicode.GetString(Encoding.UTF8.GetBytes(utf8String))


这篇关于[C#] UTF8字符串为可读的unicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆