zoukankan      html  css  js  c++  java
  • Asp.Net 简繁转换

    帮助类

    /// <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;
            }
        }

    调用方法

    string str=ChineseStringUtility.ToTraditional("我是中国人,我爱你!");
    Response.Write(str);
  • 相关阅读:
    实战篇之实现 OutLook 中以 EDM 形式发送通知邮件
    ASP.NET MVC5 之路由器
    ASP.NET MVC5 之数据迁移
    说不出的烦
    ASP.NET MVC5 之 Log4Net 的学习和使用
    读取配置文件参数和文件路径
    序列化和反序列化示例
    面向对象之封装
    面向对象4之常用的乱七八糟
    面向对象三之继承和派生
  • 原文地址:https://www.cnblogs.com/webapi/p/10516495.html
Copyright © 2011-2022 走看看