C# 中文简体转繁体实现代码

C# 中文简体转繁体实现代码,需要的朋友可以参考一下

方法一:

复制代码 代码如下:

///
 /// 中文字符工具类
 ///

 private const int LOCALE_SYSTEM_DEFAULT = 0x0800;
 private const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
 private const int LCMAP_TRADITIONAL_CHINESE = 0x04000000;

 [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
 private static extern int LCMapString(int Locale, int dwMapFlags, string lpSrcStr, int cchSrc, [Out] string lpDestStr, int cchDest);

      ///


      /// 将字符转换成简体中文
      ///

      /// 输入要转换的字符串
      /// 转换完成后的字符串
      public static string ToSimplified(string source) {
          String target = new String(' ', source.Length);
          int ret = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_SIMPLIFIED_CHINESE, source, source.Length, target, source.Length);
          return target;
      }

     ///
     /// 讲字符转换为繁体中文
     ///

     /// 输入要转换的字符串
     /// 转换完成后的字符串
     public static string ToTraditional(string source)
     {
         String target = new String(' ', source.Length);
         int ret = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TRADITIONAL_CHINESE, source, source.Length, target, source.Length);
         return target;
     }

以上就是C# 中文简体转繁体实现代码的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他教程