文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>效率比微软版好N倍的简繁转换类

效率比微软版好N倍的简繁转换类

时间:2010-11-06  来源:火地晋

using System.Runtime.InteropServices;
using System.Text;

namespace GreenLoogDS.DAL
{
    public class ChineseConverter
    {
        private static Encoding GB2312 = Encoding.GetEncoding(0x3a8);
        private const int LCMAP_SIMPLIFIED_CHINESE = 0x2000000;
        private const int LCMAP_TRADITIONAL_CHINESE = 0x4000000;

        [DllImport("kernel32.dll", EntryPoint = "LCMapStringA")]
        public static extern int LCMapString(int Locale, int dwMapFlags, byte[] lpSrcStr, int cchSrc, byte[] lpDestStr, int cchDest);
        public static string Convert(string text, ChineseConversionDirection direction)
        {
            byte[] lpSrcStr = null;
            lpSrcStr = GB2312.GetBytes(text);
            byte[] lpDestStr = new byte[lpSrcStr.Length];
            switch (direction)
            {
                case ChineseConversionDirection.TraditionalToSimplified:
                    LCMapString(0x804, LCMAP_SIMPLIFIED_CHINESE, lpSrcStr, -1, lpDestStr, lpSrcStr.Length);
                    break;
                case ChineseConversionDirection.SimplifiedToTraditional:
                    LCMapString(0x804, LCMAP_TRADITIONAL_CHINESE, lpSrcStr, -1, lpDestStr, lpSrcStr.Length);
                    break;
            }
            return GB2312.GetString(lpDestStr);
        }
    }
    public enum ChineseConversionDirection
    {
        SimplifiedToTraditional,
        TraditionalToSimplified
    }
}

 

 

相关阅读 更多 +
排行榜 更多 +
幸运硬币官方正版下载

幸运硬币官方正版下载

休闲益智 下载
宝宝来找茬手机版 v9.86.00.00 安卓版

宝宝来找茬手机版 v9.86.00.00 安卓版

休闲益智 下载
翻滚飞机大战最新版 v1.0.4 安卓版

翻滚飞机大战最新版 v1.0.4 安卓版

飞行射击 下载