参考http://blog.csdn.net/farawayplace613/archive/2008/09/14/2910527.aspx
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
}
}
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
}
}
作者:
火地晋
出处: http://yelaiju.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处: http://yelaiju.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。