110,545
社区成员
发帖
与我相关
我的任务
分享
Thread.CurrentThread.CurrentCulture.LCID
int lcid = 0x0804;
Console.WriteLine(Microsoft.VisualBasic.Strings.StrConv("问题", VbStrConv.TraditionalChinese, lcid));
Console.WriteLine(Microsoft.VisualBasic.Strings.StrConv("問題", VbStrConv.SimplifiedChinese, lcid));
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace BigCn
{
class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int LCMapString(int Locale, int dwMapFlags, byte[] lpSrcStr, int cchSrc,[Out] byte[] lpDestStr, int cchDest);
const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
const int LCMAP_TRADITIONAL_CHINESE = 0x04000000;
static void Main(string[] args)
{
Console.WriteLine(
StringConv("问题", LCMAP_TRADITIONAL_CHINESE)
);
Console.WriteLine(
StringConv("問題", LCMAP_SIMPLIFIED_CHINESE)
);
}
public static string StringConv(string chars, int LCMP_CONST)
{
Encoding ec = Encoding.Unicode;
byte[] src = ec.GetBytes(chars);
byte[] dest = new byte[src.Length];
int r = LCMapString(0x0804, LCMP_CONST, src, -1, dest, src.Length);
return ec.GetString(dest);
}
}
}
using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
public class EncodeTool
{
[DllImport("kernel32.dll", EntryPoint = "LCMapStringA")]
public static extern int LCMapString(int Locale, int dwMapFlags, byte[] lpSrcStr, int cchSrc, byte[] lpDestStr, int cchDest);
const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000;
const int LCMAP_TRADITIONAL_CHINESE = 0x04000000;
public static String ConvertString(String lines){
Encoding gb2312 = Encoding.GetEncoding(936);
byte[] src=gb2312.GetBytes(lines);
byte[] dest = new byte[src.Length];
LCMapString(0x0804, LCMAP_SIMPLIFIED_CHINESE, src, -1, dest, src.Length);
return gb2312.GetString(dest);
}
}
public static String ConvertString(String lines)
{
Encoding gb2312 = Encoding.GetEncoding(936);
byte[] src=gb2312.GetBytes(lines);
byte[] dest = new byte[src.Length];
LCMapString(0x0804, LCMAP_SIMPLIFIED_CHINESE, src, -1, dest, src.Length);
return gb2312.GetString(dest);
}