日期:2014-05-17  浏览次数:20814 次

C#十六进制转

             string text = ScreenBox.Text;
             ScreenBox.Clear();
             byte[] textToByte = Encoding.Default.GetBytes(text);
             for (int i = 0; i < textToByte.Length; i++)
                {
                    byte temp = textToByte[i];
                    string tempHex = temp.ToString("X2") + " ";
                    ScreenBox.Text += tempHex;
                }

上面的代码是将ScreenBox控件中的文本转换为十六进制并输出在ScreenBox上;然后我再将新的文本拷贝下来。

             string Hextext = ScreenBox.Text;

最后我想将Hextext字符串转换为原先的text字符串并输出,怎么写代码?谢谢。
string c# 十六进制转换

------解决方案--------------------
///<summary>
        /// 从16进制转换成汉字
        /// </summary>
        /// <param name="hex"></param>
        /// <param name="charset">编码,如"utf-8","gb2312"</param>
        /// <returns></returns>
        public static string UnHex(string hex, string charset)
        {
            if (hex == null)