zoukankan      html  css  js  c++  java
  • C#繁简转换

    //1.
    using System.Runtime.InteropServices;

     //2.
    import kernel32.dll

    [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;
     //3.转简体

    private void btnCHS_Click(object sender, EventArgs e) 
            { 
                string src = txtSrcText.Text.Trim(); 
                byte[] srcByte = Encoding.Default.GetBytes(src); 
                byte[] desByte = new byte[srcByte.Length]; 
                LCMapString(2052, LCMAP_SIMPLIFIED_CHINESE, srcByte, -1, desByte, srcByte.Length); 
                string des = Encoding.Default.GetString(desByte); 
                txtDesText.Text = des; 
            }
     //4.转繁体

    private void btnCHT_Click(object sender, EventArgs e) 
            { 
                string src = txtSrcText.Text.Trim(); 
                byte[] srcByte = Encoding.Default.GetBytes(src); 
                byte[] desByte = new byte[srcByte.Length]; 
                 
                LCMapString(2052, LCMAP_TRADITIONAL_CHINESE, srcByte, -1, desByte, srcByte.Length); 
                string des = Encoding.Default.GetString(desByte); 
                txtDesText.Text = des; 
            }
    ===============第二种=====================
    //1. 参考Microsoft.VisualBasic.dll

    //2. 转简体代码

    private void btnCHS_Click(object sender, EventArgs e) 
            { 
                string src = txtSrcText.Text.Trim(); 
                string des = Microsoft.VisualBasic.Strings.StrConv(src, Microsoft.VisualBasic.VbStrConv.SimplifiedChinese, 0); 
                txtDesText.Text = des; 
            }
    //3. 转繁体代码

    private void btnCHT_Click(object sender, EventArgs e) 
            { 
                string src = txtSrcText.Text.Trim(); 
                string des = Microsoft.VisualBasic.Strings.StrConv(src, Microsoft.VisualBasic.VbStrConv.TraditionalChinese, 0); 
                txtDesText.Text = des; 
            }

  • 相关阅读:
    codeforces 918C The Monster
    codeforces 916E Jamie and Tree dfs序列化+线段树+LCA
    FFT模板——copied from hzwer
    codeforces 899F Letters Removing set+树状数组
    Codeforces 1073GYet Another LCP Problem SA
    Codeforces 1109E Sasha and a Very Easy Test 线段树
    Codeforces 1207G Indie Album AC自动机
    HDU
    Codeforces 487E 圆方树 + 树链剖分
    Codeforces 1238G Adilbek and the Watering System 贪心
  • 原文地址:https://www.cnblogs.com/zhihai/p/2336705.html
Copyright © 2011-2022 走看看