zoukankan      html  css  js  c++  java
  • 教你如何将中文转换成全拼

    在转换之前,我们先要判断输入的是否为中文,中文字符处于4e00与9fff之间,了解了这个知识之后,我们开始操作

         /// <summary>
            /// 转化事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void button1_Click(object sender, RoutedEventArgs e)
            {
                int code = 0;
                int chfrom = Convert.ToInt32("4e00",16);
                int chend = Convert.ToInt32("9fff",16);
    
                //全拼功能
                //this.textBox2.Text = Pinyin.GetPinyin(this.textBox1.Text.ToString());
                //this.textBox2.Text = this.textBox2.Text.Replace(" ", "");
                for (int i = 0; i < this.textBox1.Text.Length; i++)
                {
                    this.textBox2.Text += this.textBox1.Text[i].ToString() + ": " + Pinyin.GetPinyin(this.textBox1.Text[i].ToString());
                }
                Encoding gb2312 = Encoding.GetEncoding("GB2312");
                for (int i = 0; i < this.textBox1.Text.Length; i++)
                {
                    string s = Pinyin.ConvertEncoding(this.textBox1.Text[i].ToString(), Encoding.UTF8, gb2312);
                    this.textBox2.Text += this.textBox1.Text[i].ToString() + Pinyin.GetInitials(s, gb2312);
                }
                for (int i = 0; i < this.textBox1.Text.Length; i++)
                {
                    code = Char.ConvertToUtf32(this.textBox1.Text[i].ToString(), 0);
                    if (code >= chfrom && code <= chend)
                        this.textBox2.Text += this.textBox1.Text[i].ToString() + " / 中文";
                }
                
    
            }

    ok,这里的转换已分为多种,难度可以说没有,微软已经大大降低了开发人员的开发难度,有利于开发人员将精力投放于业务逻辑。

  • 相关阅读:
    201. Bitwise AND of Numbers Range
    200.Number of Islands
    199. Binary Tree Right Side View
    198. House Robber
    191. Number of 1 Bits
    190. Reverse Bits
    odoo pivot filed字段设置
    postgres 实现查找所有的子记录,child_of
    postgres 查询返回记录集的函数
    python GUI编程/窗口编程之easygui
  • 原文地址:https://www.cnblogs.com/xufei/p/2943976.html
Copyright © 2011-2022 走看看