参考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://www.cnblogs.com/yelaiju/archive/2010/11/06/1870390.html,如需转载请自行联系原作者