zoukankan      html  css  js  c++  java
  • Unicode 编码解码

    1. Regex.Unescape(str);返回Unicode解码,非Unicode直接返回

    /// <summary>
          /// 2.转为Unicode编码
          /// </summary>
          /// <param name="str"></param>
          /// <returns></returns>
      public static  string ToUnicode(string str)
        {
            var  strResult = new StringBuilder();
          if (string.IsNullOrEmpty(str)) return strResult.ToString();
          foreach (var  t in str)
          {
              strResult.Append("\u");
              strResult.Append(((int)t).ToString("x"));
          }
          return strResult.ToString();
        }
          /// <summary>
          /// 3.Unicode 解码
          /// </summary>
          /// <param name="str"></param>
          /// <returns></returns>
          public static string EnUnicode(string str)
          {
              var  strResult = new StringBuilder();
              if (!string.IsNullOrEmpty(str))
              {
                  string[] strlist = str.Replace("\", "").Split('u');
                  try
                  {
                      for (int i = 1; i < strlist.Length; i++)
                      {
                          int charCode = Convert.ToInt32(strlist[i], 16);
                          strResult.Append((char)charCode);
                      }
                  }
                  catch (FormatException ex)
                  {
                      return Regex.Unescape(str);
                  }
              }
              return strResult.ToString();
          }

  • 相关阅读:
    建筑名称解释
    delphi 文件查找
    bat如何批量删除指定部分文件夹名的文件夹
    在 DELPHI 中 procedure 型变量与 method 型变量的区别
    Spearman Rank(斯皮尔曼等级)相关系数
    机器学习的MLE和MAP:最大似然估计和最大后验估计
    error “Device supports x86, but APK only supports armeabi-v7a”
    windows 安装ninja
    Gradle语法基础解析
    executing external native build for cmake
  • 原文地址:https://www.cnblogs.com/change4now/p/5351159.html
Copyright © 2011-2022 走看看