1.using System.Runtime.InteropServices;
2.import kernel32.dll
| 1 |
[DllImport("kernel32.dll", EntryPoint = "LCMapStringA")] |
| 2 |
public static extern int LCMapString(int Locale, int dwMapFlags, byte[] lpSrcStr, int cchSrc, byte[] lpDestStr, int cchDest); |
| 3 |
const int LCMAP_SIMPLIFIED_CHINESE = 0x02000000; |
| 4 |
const int LCMAP_TRADITIONAL_CHINESE = 0x04000000; |
3.转简体
| 02 |
protected void btnCHS_Click(object sender, EventArgs e) |
| 04 |
string src =TextBox1.Text.Trim(); |
| 05 |
byte[] srcByte = Encoding.Default.GetBytes(src); |
| 06 |
byte[] desByte = new byte[srcByte.Length]; |
| 07 |
LCMapString(2052, LCMAP_SIMPLIFIED_CHINESE, srcByte, -1, desByte, srcByte.Length); |
| 08 |
string des = Encoding.Default.GetString(desByte); |
4.转繁体
| 02 |
protected void btnCHZ_Click(object sender, EventArgs e) |
| 04 |
string src = TextBox1.Text.Trim(); |
| 05 |
byte[] srcByte = Encoding.Default.GetBytes(src); |
| 06 |
byte[] desByte = new byte[srcByte.Length]; |
| 07 |
LCMapString(2052, LCMAP_TRADITIONAL_CHINESE, srcByte, -1, desByte, srcByte.Length); |
| 08 |
string des = Encoding.Default.GetString(desByte); |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-622137/
,如需转载,请注明出处,否则将追究法律责任。