using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CommonUtils
{
    /// <summary>
    /// 汉字繁简体转换
    /// </summary>
    public class ChineseConverter
    {
        private const int LocaleSystemDefault = 0x0800;
        private const int LcmapSimplifiedChinese = 0x02000000;
        private const int LcmapTraditionalChinese = 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=”argSource”>繁体字符</param>
        /// <returns>简体字符</returns>
        public static string TraditionalToSimplified(string argSource)
        {
            string t = new String(\’ \’, argSource.Length);
            LCMapString(LocaleSystemDefault, LcmapSimplifiedChinese, argSource, argSource.Length, t, argSource.Length);
            return t;
        }
        /// <summary>
        /// 简体转换为繁体
        /// </summary>
        /// <param name=”argSource”>简体字符</param>
        /// <returns>繁体字符</returns>
        public static string SimplifiedToTraditional(string argSource)
        {
            string t = new String(\’ \’, argSource.Length);
            LCMapString(LocaleSystemDefault, LcmapTraditionalChinese, argSource, argSource.Length, t, argSource.Length);
            return t;
        }
    }
}

版权声明:本文为jake-ge原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/jake-ge/p/3987748.html