摘要:簡繁中文轉換
透過以下方式可以很簡單達成簡繁中文轉換:
01
internal const int LOCALE_SYSTEM_DEFAULT = 0x0800;
02
internal const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
03
internal const int LCMAP_TRADITIONAL_CHINESE = 0x04000000;
04
05
[DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
06
internal static extern int LCMapString(int Locale, int dwMapFlags, string lpSrcStr, int cchSrc, [Out] string lpDestStr, int cchDest);
07
08
public static string ToSimplified(string pSource)
09
{
10
String tTarget = new String(' ', pSource.Length);
11
int tReturn = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_SIMPLIFIED_CHINESE, pSource, pSource.Length, tTarget, pSource.Length);
12
return tTarget;
13
}
14
15
public static string ToTraditional(string pSource)
16
{
17
String tTarget = new String(' ', pSource.Length);
18
int tReturn = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TRADITIONAL_CHINESE, pSource, pSource.Length, tTarget, pSource.Length);
19
return tTarget;
20
}
internal const int LOCALE_SYSTEM_DEFAULT = 0x0800; 02
internal const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000; 03
internal const int LCMAP_TRADITIONAL_CHINESE = 0x04000000; 04
05
[DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] 06
internal static extern int LCMapString(int Locale, int dwMapFlags, string lpSrcStr, int cchSrc, [Out] string lpDestStr, int cchDest); 07
08
public static string ToSimplified(string pSource) 09
{ 10
String tTarget = new String(' ', pSource.Length); 11
int tReturn = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_SIMPLIFIED_CHINESE, pSource, pSource.Length, tTarget, pSource.Length); 12
return tTarget; 13
} 14
15
public static string ToTraditional(string pSource) 16
{ 17
String tTarget = new String(' ', pSource.Length); 18
int tReturn = LCMapString(LOCALE_SYSTEM_DEFAULT, LCMAP_TRADITIONAL_CHINESE, pSource, pSource.Length, tTarget, pSource.Length); 19
return tTarget; 20
}


