【问题标题】:Convert string with encoded UTF8 symbol into cyrillic symbol c# [duplicate]将带有编码UTF8符号的字符串转换为西里尔符号c#[重复]
【发布时间】:2017-12-19 16:37:28
【问题描述】:

来自http://ua-zip.net/script/suggest.php?prefix=61105&type=index的请求,我收到这样的答案:

"\"1 \u0410\u0441\u043a\u043e\u043b\u044c\u0434\u0456\u0432\u0441\u044c\u043a\u0438\u0439"。

对于我正在使用的请求:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FullRequestString);
    request.Method = "GET";

我收到了建设的回应:

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream stream = response.GetResponseStream())
 {
  using (StreamReader reader = new StreamReader(stream))
   {
   string line = "";
   while ((line = reader.ReadLine()) != null)
    {

如何将 \u043b 等字符转换为西里尔符号

【问题讨论】:

标签: c# utf-8 httpwebrequest


【解决方案1】:

您必须使用 HTML。尝试将所有\u 替换为&#x,例如\u0410 将变为А。不要忘记最后的分号。那么就这样做吧。

string cyrillicString = System.Net.WebUtility.HtmlDecode(your_string_with_replaced_characters);

生成的字符串将包含西里尔字符

注意: &#x 如果数字是十六进制则使用。对于十进制,只需使用&#。

【讨论】:

  • 谢谢,它有效
猜你喜欢
  • 2013-04-19
  • 2013-04-26
  • 2018-10-26
  • 2021-10-18
  • 2014-11-09
  • 1970-01-01
  • 2014-03-04
  • 2018-02-19
  • 1970-01-01
相关资源
最近更新 更多