.NET Convert from string of Hex values into Unicode characters (Support different code pages)

后端 未结 2 786
时光说笑
时光说笑 2020-12-19 15:01

I have a string of Hex values...

String hexString = \"8A65\";

I need to convert this string into their Unicode equivalents. The tricky part

2条回答
  •  误落风尘
    2020-12-19 15:57

    You need to convert the hex string to bytes (see SO post). Passing the hex string into one of the encodings to convert it to bytes just gives you the byte equivalent of those characters. I am assuming what you want is the two bytes that the 4 character string represents, so decode the hex to bytes and then you can use the encoding on the decoded bytes to get back a string.

    Encoding.{YourEncoding}.GetChars(hexBytes);
    

提交回复
热议问题