xieweikang

网上找了几个方法,但是运行之后会报错,提示要解析的字符串格式不正确。然后我猜想可能是传入的字符串 \u60a8\u4eca\u65e5\u5df2\u7b7e\u5230 中带"\"的原因,加了一行     strDecode=strDecode.Replace("\\","");  把斜杠去掉,果然,解析成功了。

 

/// <summary>
        ///作用:将16进制数据编码转化为字符串,是Encode的逆过程
        /// </summary>
        /// <param name="strDecode"></param>
        /// <returns></returns>
        public static string DecodeHexadecimalToStr(string strDecode)
        {
            string outStr = "";

            strDecode=strDecode.Replace("\\","");
            if (!string.IsNullOrEmpty(strDecode))
            {
                string[] strlist = strDecode.Replace("/", "").Split('u');
                try
                {
                    for (int i = 1; i < strlist.Length; i++)
                    {
                        //将unicode字符转为10进制整数,然后转为char中文字符  
                        outStr += (char)int.Parse(strlist[i], System.Globalization.NumberStyles.HexNumber);
                    }
                }
                catch (FormatException ex)
                {
                    outStr = ex.Message;
                }
            }
            return outStr;
        }

 

分类:

.net

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2021-07-09
  • 2022-12-23
  • 2021-09-22
  • 2021-11-17
  • 2022-01-07
猜你喜欢
  • 2021-08-02
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
  • 2021-11-17
  • 2021-08-06
  • 2022-12-23
相关资源
相似解决方案