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();
      }

Unicode 编码解码的更多相关文章

  1. Unicode编码解码在线转换工具

    // Unicode编码解码在线转换工具 Unicode 是基于通用字符集(Universal Character Set)的标准来发展,并且同时也以书本的形式(The Unicode Standar ...

  2. C# \uxxx Unicode编码解码

    /// <summary> /// Unicode编码 /// </summary> /// <param name="str"></pa ...

  3. Asp.Net \uxxx Unicode编码解码

    /// <summary> /// Unicode编码 /// </summary> /// <param name="str"></pa ...

  4. C# Unicode编码解码

    public static class CommpnHelpEx { /// <summary> /// unicode编码 /// </summary> /// <pa ...

  5. python Unicode 编码解码

    1 #将Unicode转换成普通的Python字符串:"编码(encode)" 2 unicodestring = u"Hello world" 3 utf8s ...

  6. Sql Server UniCode编码解码

    ); set @s = N'揶'; select UniCode(@s),nchar(UniCode(@s)); 在 SQL Server 中处理 Unicode 字串常数时,您必需在所有的 Unic ...

  7. C# 如何将字符串形式的” \\u1234 “ 为 “ \u1234” 的unicode编码解码为中文

    using System.Text.RegularExpressions; decodedStr = Regex.Unescape(escapeUnicodeStr);

  8. PHP解码unicode编码中文字符代码示例

    在抓取某网站数据,结果在数据包中发现了一串编码的数据:"......\u65b0\u6d6a\u5fae\u535a......", 这其实是中文被unicode编码后了的数据,想 ...

  9. PHP中对汉字进行UNICODE编码和解码的实现

    <?php /** PHP中对汉字进行UNICODE编码和解码的实现 **/ class Helper_Tool{ //php中的unicode编码转中文 static function uni ...

随机推荐

  1. 14、AppWidget及Launcher

    一.Launcher的简单研究 1 什么是Launcher Android系统启动后加载的第一个程序 . 这个程序是其他应用程序的入口 . Launcher构成: HomeScreen : (Work ...

  2. GTK+布局管理

    GTK+布局管理 GTK+ 布局管理 在本章中,我们将讲述如何将构件布置在窗口与对话框中. 当我们在设计应用程序的图形界面时,我们首先要决定的是在程序中用到哪种构件和管理应用程序中的这些构件.为了方便 ...

  3. MFC常用类

    CString CStringT 操作可变长度字符串的模板类CStringT有三个实例:CString.CStringA和CStringW,它们分别提供对TCHAR.char和wchar_t字符类型的 ...

  4. 【暑假】[深入动态规划]UVa 1627 Team them up!

    UVa 1627 Team them up! 题目: Team them up! Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Forma ...

  5. 在生成 Visual c + + 2005年或从 DLL 文件中使用 CString 派生的类的 Visual c + +.net 应用程序时,您可能会收到 LNK2019 错误消息

    http://support.microsoft.com/kb/309801

  6. OWC控件的使用

    环境:SQL Server 2005  Analysis Services + OWC 1.1 +Win 7 准备: 1.在SQL Server 2005 Analysis Services建好ola ...

  7. 【解决】Django项目废弃SQLite3拥抱MySQL

    SQLite3数据库就一个文件,拷贝着随时带走,调试方便,超级轻量级,有它的好处. 不过,MySQL才是中小项目的主流,最近想把Django里程碑项目部署到SAE上,所以试着把原来的项目数据库替换成M ...

  8. Solution for Latex error: "Cannot determine size of graphic"

    I'm trying to include graphics in my Latex-file, which I compiled with latex+dvipdf on OS X. Latex h ...

  9. 深入prototype源码之--Class

    由于工作需要项目中要用prototype框架,所以这几天捣鼓了一下,研究了一下prototype 创建对象和类以及继承的一些源码,其实早在很久以前就接触prototype,然后直接看源码, 看着太蛋疼 ...

  10. HTTP,HTTP2.0,SPDY,HTTPS你应该知道的一些事

    作为一个经常和web打交道的程序员,了解这些协议是必须的,本文就向大家介绍一下这些协议的区别和基本概念,文中可能不局限于前端知识,还包括一些运维,协议方面的知识,希望能给读者带来一些收获,如有不对之处 ...