我有一个长度为4的十六进制字符串,比如“003a”。
将其转换为 char 的最佳方法是什么?先转bytes再转char?
最佳答案
试试这个:
(char)Int16.Parse("003a", NumberStyles.AllowHexSpecifier);
或
System.Convert.ToChar(System.Convert.ToUInt32("003a", 16));
或
string str = "";
for(int i = 0; i<myHex.Length; i += 4)
str += (char)Int16.Parse(myHex.Substring(i, 4),
NumberStyles.AllowHexSpecifier);
关于C# 十六进制转char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7874127/