Unicode转换在C# [英] Unicode Conversion in 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 =http://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屋!