信息发布→ 登录 注册 退出

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

发布时间:2026-01-11

点击量:

方法一:
复制代码 代码如下:
/// <summary>
 /// 中文字符工具类
 /// </summary>
 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);

      /// <summary>
      /// 将字符转换成简体中文
      /// </summary>
      /// <param name="source">输入要转换的字符串</param>
      /// <returns>转换完成后的字符串</returns>
      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;
      }

     /// <summary>
     /// 讲字符转换为繁体中文
     /// </summary>
     /// <param name="source">输入要转换的字符串</param>
     /// <returns>转换完成后的字符串</returns>
     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;
     }

  调用上面的ToTraditiona方法就OK了~另外的那个一样的使用方法~
方法二:(推荐)
①在解决方案管理器中对应的文件夹右击“添加引用”----选择.net引用下的Microsoft.VisualBasic;
②在你要实现转换功能的aspx.cs文件中添加命名空间:using Microsoft.VisualBasic
③ 通过下面的方法可以直接实现转换,很方便吧!一句话就可以了~所以推荐这个方法
复制代码 代码如下:
 string   s   =   "繁体";
         s   =   Strings.StrConv(s,   VbStrConv.Wide,   0);   //   半角转全角
         s   =   Strings.StrConv(s,   VbStrConv.TraditionalChinese,   0);   //   简体转繁体
         s   =   Strings.StrConv(s,   VbStrConv.ProperCase ,   0);   //   首字母大写
         s   =   Strings.StrConv(s,   VbStrConv.Narrow ,   0);   //   全角转半角
         s   =   Strings.StrConv(s,   VbStrConv.SimplifiedChinese,   0);   //   繁体转简体

在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!