Convert hex string back to char

I know - there are many topics related to this, but although I looked through them, they could not understand the solution. I am converting char to hex code:

char c = i; int unicode = c; string hex = string.Format("0x{0:x4}", unicode); 

Question: how to convert hex to char back?

+7
source share
2 answers

You can try:

 hex = hex.Substring(2); // To remove leading 0x int num = int.Parse(hex, NumberStyles.AllowHexSpecifier); char cnum = (char)num; 
+19
source
 using System; using System.Globalization; class Sample { static void Main(){ char c = 'あ'; int unicode = c; string hex = string.Format("0x{0:x4}", unicode); Console.WriteLine(hex); unicode = int.Parse(hex.Substring(2), NumberStyles.HexNumber); c = (char)unicode; Console.WriteLine(c); } } 
+3
source

All Articles