• c#简体繁体转换


     方法一已经亲测,使用正常,方法二貌似不能用。

    方法一

     /// <summary>
     /// 中文字符工具类
     /// </summary>
     public static class ChineseStringUtility {
         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;
        }
     }

     

     

     

    方法二

     

    这东西虽然简单,但也不失为经典的类库,个人而言,就非常喜欢这个类库。

       用文字记录下来吧,留个记念吧

       在vs中,有一个经典的Microsoft.VisualBasic.dll的VB类库,根据官方的描述:

       它能提供对许多 .NET Framework 类的简单直观的访问,使您能够编写可与计算机、应用程序、设置、资源等交互的操作及方法代码。

      这次,写一个比较经典的东西,简体字转繁体字的操作方法,要进行操作,先引用类库.

      我们可以在项目中引用Microsoft.VisualBasic.dll就可以了

     

     

    实现简体繁体转换方法:

    Microsoft.VisualBasic.Strings.StrConv(string str, VbStrConv Conversion, int LocaleID);

    简繁转换,只是枚举值不一样而以

    简体转繁体:Microsoft.VisualBasic.Strings.StrConv(string str, VbStrConv.TraditionalChinese,0) 
    繁体转简体:Microsoft.VisualBasic.Strings.StrConv(string str VbStrConv.SimplifiedChinese,0)

    Str: 要转换的 String 表达式。 
    Conversion: Microsoft.VisualBasic.VbStrConv。指定要执行的转换类型的枚举值。 
    LocaleID: LocaleID 值(如果与系统 LocaleID 值不同)。(系统 LocaleID 值为默认值。)

    实际使用怎样?那么我们做一个测试

        class Program
        {
            static void Main(string[] args)
            {
                Console.Write(Microsoft.VisualBasic.
                 Strings.StrConv("博客园",
                 Microsoft.VisualBasic.VbStrConv.TraditionalChinese, 0));
                Console.Read();
            }
        }

    转载自:http://blog.csdn.net/weiqian000/article/details/5565415 

  • 相关阅读:
    关机相关(shutdown,reboot)
    软件架构学习小结
    颜色空间RGB与HSV(HSL)的转换
    OData语法
    拷贝构造函数,深拷贝,大约delete和default相关业务,explicit,给定初始类,构造函数和析构函数,成员函数和内联函数,关于记忆储存,默认参数,静态功能和正常功能,const功能,朋友
    登录模块
    TextView 使用自定义的字体和亮点
    基于Hama并联平台Finding a Maximal Independent Set 设计与实现算法
    VS2012使用XListCtrl
    ThinkPHP 3.2 开放 cache注缓存,过滤非法字符
  • 原文地址:https://www.cnblogs.com/dmhp/p/5392257.html
Copyright © 2020-2023  润新知