Unicode转换在C# [英] Unicode Conversion in c#

查看:154
本文介绍了Unicode转换在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图分配的Unicode字符串上,但它返回Привет字符串DYN€Ð¸Ð²ÐμÑ,但我需要Привет,我按下面的函数转换。

i am trying to assign Unicode on string but it return "Привет" string as "Привет" But i need "Привет", i am converting by following function .

public string Convert(string str)
{
    byte[] utf8Bytes = Encoding.UTF8.GetBytes(str);
    str = Encoding.UTF8.GetString(utf8Bytes);
    return str;
}



我能为解决这个问题,退换货Привет做的。

what can i do for solve this problem to return "Привет".

推荐答案

П是Unicode字符的 0x041F ,其UTF-8编码产生的 0xD0 0x9F HREF =htt​​p://forumtreff.pytalhost.de/viewtopic.php?f=47&t=66&start=2> DY

П is Unicode character 0x041F, and its UTF-8 encoding is 0xD0 0x9F resulting in П.

由于函数只返回输入参数,正如已经讨论提意见,我认为你的原始输入字符串实际上是UTF-8,并且希望将其转换成原生.NET字符串。

Since the function only returns the input parameter, as commenters already discussed, I conclude that your original input string is actually in UTF-8, and you want to convert it into native .Net string.

在哪里原始字符串从何而来?

Where does the original string come from?

而不是读取输入为C#字符串,更改您的代码读取字节[] ,然后调用 Encoding.UTF8.GetString(inputUtf8ByteArray)

Instead of reading the input into a C# string, change your code to read a byte[], and then call Encoding.UTF8.GetString(inputUtf8ByteArray).

这篇关于Unicode转换在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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