简繁体中文的转换和拼音转换

需要获取  ChineseConverter.dll 和 ChnCharInfo.dll 这两个DLL 

可以点击名称下载,也可以通过下载Microsoft Visual Studio International Pack 安装获得这两个DLL

第二种方式请自行搜索下载

以下为测试代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
using Microsoft.International.Converters.PinYinConverter;

namespace ChineseConvertTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void GetTraditional_Click(object sender, EventArgs e)
        {
            if (txtSimple.Text == "")
            {
                MessageBox.Show("请输入需要转换的中文简体"); return;
            }
             char[] CharSimples = txtSimple.Text.Trim().ToCharArray();

             for (int i = 0; i < CharSimples.Length; i++)
             {
                 if (ChineseChar.IsValidChar(CharSimples[i]))
                 {
                     txtTraditional.Text += ChineseConverter.Convert(CharSimples[i].ToString(), ChineseConversionDirection.SimplifiedToTraditional);
                 }
                 else
                 {
                     txtTraditional.Text += CharSimples[i].ToString();
                 }
             }
        }

        private void txtSimple_TextChanged(object sender, EventArgs e)
        {
            //int count = 0;
            //string simple = "";
            //string BiHua = "";
            //string PinYin = "";

            //char[] CharSimples = txtSimple.Text.Trim().ToCharArray();

            //for (int i = 0; i < CharSimples.Length; i++)
            //{
            //    if (ChineseChar.IsValidChar(CharSimples[i]))
            //    {
            //        count++;
            //        simple += CharSimples[i].ToString();
            //        BiHua += ChineseChar.GetStrokeNumber(CharSimples[i]).ToString() + ",";
            //        ChineseChar CC = new ChineseChar(CharSimples[i]);
            //        PinYin += CC.Pinyins[0].Substring(0, CC.Pinyins[0].Length - 1) + ",";
            //    }
            //    else
            //    {
            //        MessageBox.Show("输入的汉字不合法");
            //        continue;
            //    }
            //}

            //label3.Text = string.Format("共有有效汉字{0}个", count);

            //txtTraditional.Text = ChineseConverter.Convert(simple, ChineseConversionDirection.SimplifiedToTraditional);

            //txtBiHua.Text = BiHua.Substring(0, BiHua.Length - 1);

            //txtPinYin.Text = PinYin.Substring(0, PinYin.Length - 1);

        }

        private void GetBiHua_Click(object sender, EventArgs e)
        {
            string BiHua = "";

            char[] CharSimples = txtSimple.Text.Trim().ToCharArray();

            for (int i = 0; i < CharSimples.Length; i++)
            {
                if (ChineseChar.IsValidChar(CharSimples[i]))
                {
                    BiHua += ChineseChar.GetStrokeNumber(CharSimples[i]).ToString() + ",";
                }
                else
                {
                    BiHua += "?,";
                }
            }
            txtBiHua.Text = BiHua.Substring(0, BiHua.Length - 1);
        }

        private void GetPinYin_Click(object sender, EventArgs e)
        {
            string PinYin = "";

            char[] CharSimples = txtSimple.Text.Trim().ToCharArray();

            for (int i = 0; i < CharSimples.Length; i++)
            {
                if (ChineseChar.IsValidChar(CharSimples[i]))
                {
                    ChineseChar CC = new ChineseChar((CharSimples[i]));
                    PinYin += CC.Pinyins[0].Substring(0, CC.Pinyins[0].Length - 1) + ",";
                }
                else
                {
                    PinYin += "? ,";
                }
            }
            txtPinYin.Text = PinYin.Substring(0, PinYin.Length - 1);
        }

    }
}
View Code

 

 

以下为测试界面

 

转载于:https://www.cnblogs.com/ShuiMu/articles/3393767.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值