参考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
    }
}

 

 

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2021-12-04
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
猜你喜欢
  • 2022-02-11
  • 2021-11-20
  • 2021-09-29
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案