Best way to decode hex sequence of unicode characters to string

11,430

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);
Share:
11,430
Valentin V
Author by

Valentin V

Fraud detection at fingerprintjs.com Building open source tools and SaaS to empower developers to stop online fraud. Stop fraud, spam, and account takeovers with 99.5% accurate browser fingerprinting as a service.

Updated on June 04, 2022

Comments

  • Valentin V
    Valentin V almost 2 years

    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.