public static string ConvertHexToString(string source)
        {
            byte[] oribyte = new byte[source.Length/2];
            for(int i=0;i<source.Length;i+=2)
            {
                string str = Convert.ToInt32(source.Substring(i,2),16).ToString();
                oribyte[i/2] = Convert.ToByte(source.Substring(i,2),16);
            }
            return System.Text.Encoding.Default.GetString(oribyte);
        }这段代码,关键的地方,后面帮注上注释谢谢。。

解决方案 »

  1.   


        public static string ConvertHexToString(string source) 
            { 
                byte[] oribyte = new byte[source.Length/2];      //生成一个字符串“字符个数”的一半长度的字节数组
                for(int i=0;i <source.Length;i+=2) 
                { 
                    //提取两个字符,解释成16进制数,可以猜测source中是形如:FF3A2b16之类的16进制串
                      //这里上把提取出来的两个字符,先转换成整数,比如:FF转换成256,再输出。
                    string str = Convert.ToInt32(source.Substring(i,2),16).ToString(); 
                    //这里是转换为一个byte,填充进去。
                    oribyte[i/2] = Convert.ToByte(source.Substring(i,2),16); 
                } 
               //返回由这个oribyte组成的字符串
                return System.Text.Encoding.Default.GetString(oribyte); 
            } 
    可以猜测,source是某个字符的16进制编码串。
      

  2.   

    举个例子来说:
    我爱你
    使用系统默认的编码格式(936)编码后的16进制串为:
    CED2B0AEC4E3
    用这个字符串(CED2B0AEC4E3)调用你的函数,将返回“我爱你”这个字符。
      

  3.   

        private void SchoolFlagUrl()
        {
            schoolid = Hxzp.CommonFile.StringHelper.ConvertHexToString(Request.QueryString["SchoolID"].ToString());
            string[] sArray = schoolid.Split('&');
            schoolpicture = bll.byIdSchoolFlag(int.Parse(sArray[0].ToString()));
            schoolpicture = Hxzp.CommonFile.SetAll.setimgurl(schoolpicture).ToString();
        }上面调用到的一个ConvertHexToString函数(你解释的“我爱你。。CED2B0AEC4E3 。之类的”)
    想问一下,上面的代码schoolid.Split('&')这个返回的都是数组吗?你解释的“CED2B0AEC4E3 ”不是数组吧。
    为什么用数组?(那代码帮我解释下,好吗?)