string l = textBox1.Text;
string c = HttpUtility.HtmlDecode(l);
MessageBox.Show(c);假设文本框中输入的是\u7f51\u7edc\u7535\u8bdd,但这里输出的还是\u7f51\u7edc\u7535\u8bdd,并没有解码
如何才能解码

解决方案 »

  1.   

    System.Web.HttpUtility.HtmlAttributeEncode(textBox1.Text);
      

  2.   

    我的要求是在文本框中输入\u7f51\u7edc\u7535\u8bdd,然后取文本框中的值解码! 3楼的没看清楚!4楼的效果没变,还是输出\u7f51\u7edc\u7535\u8bdd。
      

  3.   

    Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
    string s=reg.Replace(SourceString, delegate(Match m) { return ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString();
    Console.Write("\u7f51\u7edc") 网络
      

  4.   

       private void button1_Click(object sender, EventArgs e)
            {
             
                string _TextPear = DecodeUnicode(textBox1.Text);
             
                
            }
            public string DecodeUnicode(string p_Text)
            {
                string _ReturnValue = p_Text;
                System.Text.RegularExpressions.MatchCollection _Collection = new System.Text.RegularExpressions.Regex(@"(?<=\\u)(\w{4,16})+").Matches(p_Text);
                foreach (System.Text.RegularExpressions.Match _Match in _Collection)
                {
                    char _Char =(char)Convert.ToUInt16(_Match.Value,16);
                    _ReturnValue=_ReturnValue.Replace("\\u" + _Match.Value, _Char.ToString());
                }            return _ReturnValue;
            }
      

  5.   

    谢谢zgke,非常感谢。用你10楼的代码OK了!