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

为什么同样是去掉空字符,换个方法就不能输出了呢?
原方法是这样的
[code=C#]  
                ///   16进制转换成字符串  
                public   static   string   HexStringToString(string   hs)
                {
                        //以%分割字符串,并去掉空字符
                        string[]   chars   =   hs.Split(new   char[]   {   '% '   },   StringSplitOptions.RemoveEmptyEntries);
                        byte[]   b   =   new   byte[chars.Length];
                        //逐个字符变为16进制字节数据
                        for   (int   i   =   0;   i   <   chars.Length;   i++)
                        {
                                b[i]   =   Convert.ToByte(chars[i],   16);
                        }
                        //按照指定编码将字节数组变为字符串
                        return   Encoding.GetEncoding( "GB2312 ").GetString(b,   0,   b.Length);

                }[/code]
我把它改成了这样
[code=C#]   public   static   string   HexStringToString(string   hs)
                {
                        //以%分割字符串,并去掉空字符                                
                        hs.Trim();
                        string[]   chars   =   hs.Split(new   char[]   {   '% '   });
                        byte[]   b   =   new   byte[chars.Length];
                        //逐个字符变为16进制字节数据
                        for   (int   i   =1;   i   <   chars.Length;   i++)
                        {
                                b[i]   =   Convert.ToByte(chars[i],   16);
                                MessageBox.Show(chars[i]);
                        }
                        //按照指定编码将字节数组变为字符串
&