怎么将文本中的\uxxxx转换成中文?

解决方案 »

  1.   

    HttpUtility.HtmlDecode("\u6B56dfdf\u6A56")
      

  2.   


    在web页面中可以,放到类库中使用替换不了。。
      

  3.   

    System.Text.Encoding.Unicode.GetString(***)
      

  4.   


    那是因为你没有引用System.Web.dll
      

  5.   

    字符串转换为Unicode编码:string source = TextBox1.Text;               //"我爱你"
    string dest = "";
    Encoding code = Encoding.GetEncoding("unicode");        
    byte[] arr = code.GetBytes(source);foreach (byte ch in arr)
           dest += Convert.ToString(ch, 16);TextBox2.Text = dest;
      

  6.   

    上L弄错了,,,public static string ToGB2312(string str)
        {
            string r = "";
            MatchCollection mc = Regex.Matches(str, @"\\u([\w]{2})([\w]{2})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            byte[] bts = new byte[2];
            foreach(Match m in mc )
            {
                bts[0] = (byte)int.Parse(m.Groups[2].Value, NumberStyles.HexNumber);
                bts[1] = (byte)int.Parse(m.Groups[1].Value, NumberStyles.HexNumber);
                r += Encoding.Unicode.GetString(bts);
            }
            return r;
        }