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

C#解码,16进制的,类似\u5317\u4eac
如何用C#解码,这是javascrip编号后的数据:\u5317\u4eac 对应 北京

如何用c#实现解密啊?

------解决方案--------------------
C# code

 string num = @"\u5317\u4eac";
 string xnum = Regex.Unescape(num);//北京

------解决方案--------------------
楼上的正解,我给个反的

C# code
     /// <summary>
        /// 从汉字转换到16进制
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string GetHexFromChs(string s)
        {
            if ((s.Length % 2) != 0)
            {
                s += " ";//空格
                //throw new ArgumentException("s is not valid chinese string!");
            }

            System.Text.Encoding chs = System.Text.Encoding.GetEncoding("gb2312");

            byte[] bytes = chs.GetBytes(s);

            string str = "";

            for (int i = 0; i < bytes.Length; i++)
            {
                str += string.Format("{0:X}", bytes[i]);
            }

            return str;
        }