将unicode字符的十六进制序列解码为字符串的最佳方法

时间:2022-06-14 21:41:25

What is the most code free way to decode a string:

解码字符串最无代码的方法是什么:

\xD0\xAD\xD0\xBB\xD0\xB5\xD0\xBA\xD1\x82\xD1\x80\xD0\xBE\xD0\xBD\xD0\xBD\xD0\xB0\xD1\x8F

to human string in C#?

C#中的人字符串?

This hex string contains some unicode symbols.

此十六进制字符串包含一些unicode符号。

I know about

我知道

System.Convert.ToByte(string, fromBase);

But I was wondering if there are some built-in helpers that asp.net internally uses.

但我想知道asp.net内部是否有一些内置助手。

Thank you.

1 个解决方案

#1


4  

In this site you are not likely to get a code free way (it's about code). Decoding a hex encoded byte array is possible if you know the original encoding.

在这个站点中,您不太可能获得免代码方式(它是关于代码的)。如果您知道原始编码,则可以解码十六进制编码的字节数组。

Guessing the encoding to be UTF8, decoding it with System.Text.UTF8encoding yields the following 11 unicode characters Cyrillic string:

猜测编码为UTF8,用System.Text.UTF8encoding解码它产生以下11个unicode字符西里尔字符串:

CYRILLIC CAPITAL LETTER E, CYRILLIC SMALL LETTER EL, CYRILLIC SMALL LETTER IE, CYRILLIC SMALL LETTER KA, CYRILLIC SMALL LETTER TE, CYRILLIC SMALL LETTER ER, CYRILLIC SMALL LETTER O, CYRILLIC SMALL LETTER EN, CYRILLIC SMALL LETTER EN, CYRILLIC SMALL LETTER A, CYRILLIC SMALL LETTER YA,

CYRILLIC CAPITAL LETTER E,CYRILLIC SMALL LETTER EL,CYRILLIC SMALL LETTER IE,CYRILLIC SMALL LETTER KA,CYRILLIC SMALL LETTER TE,CYRILLIC SMALL LETTER ER,CYRILLIC SMALL LETTER O,CYRILLIC SMALL LETTER EN,CYRILLIC SMALL LETTER EN,CYRILLIC SMALL LETTER A, CYRILLIC SMALL LETTER YA,

Once you figure how to get your data into a Byte[], the sample code in the above reference shows the way:

一旦你想出如何将数据放入Byte [],上面参考中的示例代码就会显示出来:

// fill encodedBytes with original data
Byte[] encodedBytes = new Byte[] {0xD0,0xAD,0xD0,0xBB,0xD0,0xB5}; //...
UTF8Encoding utf8 = new UTF8Encoding();
String decodedString = utf8.GetString(encodedBytes);

#1


4  

In this site you are not likely to get a code free way (it's about code). Decoding a hex encoded byte array is possible if you know the original encoding.

在这个站点中,您不太可能获得免代码方式(它是关于代码的)。如果您知道原始编码,则可以解码十六进制编码的字节数组。

Guessing the encoding to be UTF8, decoding it with System.Text.UTF8encoding yields the following 11 unicode characters Cyrillic string:

猜测编码为UTF8,用System.Text.UTF8encoding解码它产生以下11个unicode字符西里尔字符串:

CYRILLIC CAPITAL LETTER E, CYRILLIC SMALL LETTER EL, CYRILLIC SMALL LETTER IE, CYRILLIC SMALL LETTER KA, CYRILLIC SMALL LETTER TE, CYRILLIC SMALL LETTER ER, CYRILLIC SMALL LETTER O, CYRILLIC SMALL LETTER EN, CYRILLIC SMALL LETTER EN, CYRILLIC SMALL LETTER A, CYRILLIC SMALL LETTER YA,

CYRILLIC CAPITAL LETTER E,CYRILLIC SMALL LETTER EL,CYRILLIC SMALL LETTER IE,CYRILLIC SMALL LETTER KA,CYRILLIC SMALL LETTER TE,CYRILLIC SMALL LETTER ER,CYRILLIC SMALL LETTER O,CYRILLIC SMALL LETTER EN,CYRILLIC SMALL LETTER EN,CYRILLIC SMALL LETTER A, CYRILLIC SMALL LETTER YA,

Once you figure how to get your data into a Byte[], the sample code in the above reference shows the way:

一旦你想出如何将数据放入Byte [],上面参考中的示例代码就会显示出来:

// fill encodedBytes with original data
Byte[] encodedBytes = new Byte[] {0xD0,0xAD,0xD0,0xBB,0xD0,0xB5}; //...
UTF8Encoding utf8 = new UTF8Encoding();
String decodedString = utf8.GetString(encodedBytes);