哪位有把\u2344\u5435\u9876这个转换为汉字的?

解决方案 »

  1.   

    C#十六进制转换为汉字
    private string hexstr2str(string hexstring)
            {
                System.Text.Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
                byte[] b = new byte[hexstring.Length / 2];
                for (int i = 0; i < hexstring.Length / 2; i++)
                {
                    b[i] = Convert.ToByte("0x" + hexstring.Substring(i * 2, 2), 16);
                }
                return encode.GetString(b);
            }        private string getultstr(string strcontent)
            {
                string aaa = strcontent;
                int lenth = aaa.Length;
                for (int i = lenth - 2; i >= 0; i -= 2)
                {
                    aaa = aaa.Insert(i, "0x");
                }
                int z = aaa.Length / 4;
                byte[] asdf = new byte[z];
                for (int i = 0; i < z; i++)
                {
                    asdf[i] = Convert.ToByte(aaa.Substring(0, 4), 16);
                    aaa = aaa.Substring(4);
                }
                return System.Text.Encoding.Default.GetString(asdf);
            }        public string ConvertTo_UTF8_String(string Msg)
            {
                byte[] buff = new byte[Msg.Length / 2];
                string Message = "";
                for (int i = 0; i < buff.Length; i++)
                {
                    buff[i] = byte.Parse(Msg.Substring(i * 2, 2), System.Globalization.NumberStyles.AllowHexSpecifier);
                }
                Message = System.Text.UTF8Encoding.UTF8.GetString(buff);
                return Message;
            }
      

  2.   

    你的是十六进制?试试这个
    public   static   string   GetChsFromHex(string   hex)   
      {   
      if   (hex   ==   null)   
      throw   new   ArgumentNullException("hex");   
      if   (hex.Length   %   2   !=   0)   
      throw   new   ArgumentException("hex   is   not   a   valid   number!",   "hex");   
      //   需要将   hex   转换成   byte   数组。   
      byte[]   bytes   =   new   byte[hex.Length   /   2];   
        
      for   (int   i   =   0;   i   <   bytes.Length;   i++)     
      {   
      try     
      {   
      //   每两个字符是一个   byte。   
      bytes[i]   =   byte.Parse(hex.Substring(i   *   2,   2),   
      System.Globalization.NumberStyles.HexNumber);   
      }     
      catch     
      {   
      //   Rethrow   an   exception   with   custom   message.   
      throw   new   ArgumentException("hex   is   not   a   valid   hex   number!",   "hex");   
      }   
      }   
        
      //   获得   GB2312,Chinese   Simplified。   
      System.Text.Encoding   chs   =   System.Text.Encoding.GetEncoding("gb2312");   
        
        
      return   chs.GetString(bytes);   
      }  
      

  3.   

    /// <summary>
    /// 将Unicode字串\u....\u....格式字串转换为原始字符串
    /// </summary>
    /// <param name="srcText"></param>
    /// <returns></returns>
    private string UnicodeToString(string srcText)
    {
        string dst = "";
        string src = srcText;
        int len = srcText.Length / 6;
        
        for (int i = 0; i <= len - 1; i++)
        {
            string str = src.Substring(0, 6).Substring(2);
            src = src.Substring(6);
            byte[] bytes = new byte[2];
            bytes[1] = byte.Parse(int.Parse(str.Substring(0, 2), System.Globalization.NumberStyles.HexNumber).ToString());
    bytes[0] = byte.Parse(int.Parse(str.Substring(2, 2), System.Globalization.NumberStyles.HexNumber).ToString());
            dst += System.Text.Encoding.Unicode.GetString(bytes);
        }
        return dst;
    }
    调用:string src = @"\u2344\u5435\u9876";
    string ret = UnicodeToString(str);
      

  4.   

    System.Text.Encoding.Unicode.GetString(byte[]) 
    private string GetGB(string HexStr){
    byte[] b = new byte[HexStr.Length/2];
    for(int i=0;i<HexStr.Length;i+=2)
    {
    string str = Convert.ToInt32(HexStr.Substring(i,2),16).ToString();
    b[i/2] = Convert.ToByte(HexStr.Substring(i,2),16);
    }
    return System.Text.Encoding.Default.GetString(b);
    }
      

  5.   

    做了个方法可试试    class Program
        {
            static void Main(string[] args)
            {
                String decodedString = DecodedString(@"\u2344\u5435\u9876");//将字节数组解码
                Console.WriteLine("Decoded String:" + decodedString); //解码结果:?吵顶
                Console.ReadLine();
            }        //单字符转换
            private static ushort GetByte(char ch)
            {
                ushort rtnNum = 0;
                switch (ch)
                {
                    case 'a':
                    case 'A': rtnNum = 10; break;
                    case 'b':
                    case 'B': rtnNum = 11; break;
                    case 'c':
                    case 'C': rtnNum = 12; break;
                    case 'd':
                    case 'D': rtnNum = 13; break;
                    case 'e':
                    case 'E': rtnNum = 14; break;
                    case 'f':
                    case 'F': rtnNum = 15; break;
                    default: rtnNum = ushort.Parse(ch.ToString()); break;            }
                return rtnNum;
            }
            
            /// <summary>
            /// 转换一个字符
            /// </summary>
            /// <param name="unicodeSingle"></param>
            /// <returns></returns>
            private  static string ConvertSingle(string unicodeSingle)
            {
                if (unicodeSingle.Length!=4) 
                    return null ;
                  byte[] unicodeBytes = new byte[2]{ 0, 0 };
                  for (int i = 0; i < 4; i++)
                  {
                      switch (i)
                      {
                          case 0: unicodeBytes[1] += (byte)(GetByte(unicodeSingle[i]) * 16); break;
                          case 1: unicodeBytes[1] += (byte)GetByte(unicodeSingle[i]); break;
                          case 2: unicodeBytes[0] += (byte)(GetByte(unicodeSingle[i]) * 16); break;
                          case 3: unicodeBytes[0] += (byte)GetByte(unicodeSingle[i]); break;
                      }
                  }
                  return Encoding.Unicode.GetString(unicodeBytes);
            }
            private static String DecodedString(String str)
            {            String[] aStr = str.Split(new String []{ @"\u"},StringSplitOptions.RemoveEmptyEntries);
                StringBuilder sb = new StringBuilder();
                if (aStr.Length > 0)
                {
                    for (int i = 0; i < aStr.Length; i++)
                    {
                        sb.Append(ConvertSingle(aStr[i]));
                    }
                }
                return sb.ToString();
            }
        }