繁简体转换
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace CommonUtils
{
/// <summary>
/// 汉字繁简体转换
/// </summary>
public class ChineseConverter
{
private const int LocaleSystemDefault = 0x0800;
private const int LcmapSimplifiedChinese = 0x02000000;
private const int LcmapTraditionalChinese = 0x04000000;
[DllImport(“kernel32”, CharSet = CharSet.Auto, SetLastError = true)]
private static extern int LCMapString(int locale, int dwMapFlags, string lpSrcStr, int cchSrc, [Out] string lpDestStr, int cchDest);
/// <summary>
/// 繁体转换为简体
/// </summary>
/// <param name=”argSource”>繁体字符</param>
/// <returns>简体字符</returns>
public static string TraditionalToSimplified(string argSource)
{
string t = new String(\’ \’, argSource.Length);
LCMapString(LocaleSystemDefault, LcmapSimplifiedChinese, argSource, argSource.Length, t, argSource.Length);
return t;
}
/// <summary>
/// 简体转换为繁体
/// </summary>
/// <param name=”argSource”>简体字符</param>
/// <returns>繁体字符</returns>
public static string SimplifiedToTraditional(string argSource)
{
string t = new String(\’ \’, argSource.Length);
LCMapString(LocaleSystemDefault, LcmapTraditionalChinese, argSource, argSource.Length, t, argSource.Length);
return t;
}
}
}