32 lines
985 B
C#
32 lines
985 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AllBase.Util;
|
|
|
|
public class ChineseStringConverter
|
|
{
|
|
private const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
|
|
private const int LCMAP_TRADITIONAL_CHINESE = 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);
|
|
|
|
public static string ToSimplified(string source)
|
|
{
|
|
string target = new string(' ', source.Length);
|
|
LCMapString(0x0800, LCMAP_SIMPLIFIED_CHINESE, source, source.Length, target, source.Length);
|
|
return target;
|
|
}
|
|
|
|
public static string ToTraditional(string source)
|
|
{
|
|
string target = new string(' ', source.Length);
|
|
LCMapString(0x0800, LCMAP_TRADITIONAL_CHINESE, source, source.Length, target, source.Length);
|
|
return target;
|
|
}
|
|
}
|