tags:

views:

4699

answers:

1

Hello,

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#?

This hex string contains some unicode symbols.

I know about

System.Convert.ToByte(string, fromBase);

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

Thank you.

+3  A: 

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:

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:

// fill encodedBytes with original data
Byte[] encodedBytes = new Byte[] {0xD0,0xAD,0xD0,0xBB,0xD0,0xB5}; //...
UTF8Encoding utf8 = new UTF8Encoding();
String decodedString = utf8.GetString(encodedBytes);
gimel
Hello, gimel.Yes, the text is russian.I know about your approach, was just wondering if there is some waythat looks like:System.Web.SomeFancyHttpUtil.FromHexUnicodeEscapeSequence(string s);:-)
Valentin Vasiliev