I have a string of Hex values...
String hexString = "8A65";
I need to convert this string into their Unicode equivalents. The tricky part is that I need to support different code pages and some code pages have '8A65' = one character whereas other code pages would convert it into two characters.
I have no prior knowledge of which code page I will be using until I need to perform the conversion.
I've tried all sorts of stuff such as
byte[] original = Encoding.Unicode.GetBytes(hexString);
byte[] conv= Encoding.Convert(Encoding.Unicode, Encoding.GetEncoding(932), orig);
char[] chars = Encoding.GetEncoding(932).GetChars(conv);
Note: code page 932 is Japanese
SOLUTION
string hexString = "8A65";
int length = hexString.length;
byte[] bytes = new byte[length / 2];
for (int i = 0; i < length; i += 2)
{
bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16);
}
char[] chars = Encoding.GetEncoding(932).GetChars(bytes);
Thank you pstrjds, you are a life saver!