将hex字符串转换回char
我知道 – 关于这一点有很多主题,但即使我看了一堆它们也无法找到解决方案..我正在将char转换为hex,如下所示:
char c = i; int unicode = c; string hex = string.Format("0x{0:x4}", unicode);
问题:如何将hex转换为char?
你可以尝试:
hex = hex.Substring(2); // To remove leading 0x int num = int.Parse(hex, NumberStyles.AllowHexSpecifier); char cnum = (char)num;
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); } }