日期:2014-05-18  浏览次数:20743 次

Unicode编码 转成ASCII
\n&nbsp;&nbsp;&nbsp;&nbsp;&#22823;&#31163;&#29579;&#26397;&#65292;&#40857;&#28170;&#30465;&#65292;&#31532;&#19968;&#22823;&#19990;&#23478;&#65292;&#26041;&#23478;&#30340;&#20869;&#24220;&amp;ldqo;&#19975;&#35937;&#22253;&amp;rdqo;&#20043;&#20013;&#65292;&#28165;&#26216;&#30340;&#38654;&#27668;&#36824;&#27809;&#26377;&#25955;&#21435;&#65292;&#19968;&#32676;&#26041;&#23478;&#23376;&#24351;&#65292;&#23601;&#24320;&#22987;&#20102;&#26089;&#19978;&#30340;&#20064;&#27494;&#65292;&#26216;&#32451;&#12290;<br />\r\n<br />\r


把这里面的Unicode转成汉字 怎么弄 其他的<br />\r\n<br />\r保持不动

------解决方案--------------------
C# code
  /// <summary>
    /// 将Unicode转换为汉字
    /// </summary>
    /// <param name="name">要转换的字符串</param>
    /// <returns></returns>
    public string UnicodeToGB(string text)
    {
        MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");
        if (mc != null && mc.Count > 0)
        {
            StringBuilder sb = new StringBuilder();
            foreach (Match m2 in mc)
            {
                string v = m2.Value;
                string word = v.Substring(2);
                byte[] codes = new byte[2];
                int code = Convert.ToInt32(word.Substring(0, 2), 16);
                int code2 = Convert.ToInt32(word.Substring(2), 16);
                codes[0] = (byte)code2;
                codes[1] = (byte)code;
                sb.Append(Encoding.Unicode.GetString(codes));
            }
            return sb.ToString();
        }
        else
        {
            return text;
        }
    }