中文繁简互换以及获取中文字符串首字母

1、经常会遇到简体变繁体、繁体变简体和取中文字符串首字母的需求,最近整理了一个公共类,给大家分享。运行效果:

2、调用方法,代码如下:

        /// <summary>
        /// 简体变繁体
        /// </summary>
        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(textBox1.Text))
                textBox2.Text = textBox1.Text.ToTraditional();
            else
                MessageBox.Show("请输入简体字!");
        }

        /// <summary>
        /// 繁体变简体
        /// </summary>
        private void button2_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(textBox2.Text))
                textBox1.Text = textBox2.Text.ToSimplified();
            else
                MessageBox.Show("请输入繁体字!");
        }

        //取首字母
        private void button3_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(textBox3.Text))
                textBox4.Text = textBox3.Text.GetChineseFristSpell().ToUpper();
            else
                MessageBox.Show("请在左侧框输入汉字!");
        }

3、其中简繁互换,引用了Microsoft.VisualBasic。完整工具类及案例,已整理发布,公共类名称为ChineseUtils。下载链接(无需积分):http://download.csdn.net/detail/kehaigang29/8868967

原文地址:https://www.cnblogs.com/ManchesterUnitedFootballClub/p/4621193.html