汉字转拼音。简繁体互转。ChnCharInfo.dll,ChineseConverter.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.PinYinConverter;

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

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (char item in txtinput.Text.Trim())
            {
                ChineseChar ch = new ChineseChar(item);
                txtout.AppendText(ch.Pinyins[0].Substring(0, ch.Pinyins[0].Length - 1) + "\t" + ch.Pinyins[0].Substring(0, 1) + "\r\n");
            }
            
        }
    }
}


 

简繁体互转

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;

namespace 汉字转换
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            txtout.Text = ChineseConverter.Convert(txtinput.Text, ChineseConversionDirection.SimplifiedToTraditional);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            txtinput.Text = ChineseConverter.Convert(txtout.Text, ChineseConversionDirection.TraditionalToSimplified);
        }
    }
}


 

 

1)支持获取简体中文字符的常用属性:拼音多音字,同音字,笔画 2)繁简中文互相化 public string Convert (string chr) { try{ if (chr.Length != 0) { StringBuilder fullSpell = new StringBuilder (); for (int i=0; i<chr.Length; i++) { bool isChineses = Microsoft.International.Converters.PinYinConverter.ChineseChar.IsValidChar(chr[i]); if (isChineses) { Microsoft.International.Converters.PinYinConverter.ChineseChar chineseChar = new Microsoft.International.Converters.PinYinConverter.ChineseChar (chr [i]); foreach (string value in chineseChar.Pinyins) { if (!string.IsNullOrEmpty (value)) { fullSpell.Append (value.Remove(value.Length - 1, 1)); break; } } }else { fullSpell.Append(chr[i]); } } return fullSpell.ToString().ToUpper(); } }catch(Exception e){ Console.WriteLine("全拼化出错!"+e.Message); } return string.Empty; } /// <summary> /// 获取首字母 /// </summary> public string SubFirstLetter(string chr) { try{ chr = chr.Substring(0,1); if (chr.Length != 0) { StringBuilder fullSpell = new StringBuilder (); for (int i=0; i<chr.Length; i++) { bool isChineses = Microsoft.International.Converters.PinYinConverter.ChineseChar.IsValidChar(chr[i]); if (isChineses) { Microsoft.International.Converters.PinYinConverter.ChineseChar chineseChar = new Microsoft.International.Converters.PinYinConverter.ChineseChar(chr[i]); foreach (string value in chineseChar.Pinyins) { if (!string.IsNullOrEmpty (value)) { fullSpell.Append (value.Remove(value.Length - 1, 1)); break; } } }else { fullSpell.Append(chr[i]); } } return fullSpell.ToString().Substring(0,1).ToUpper(); } }catch(Exception e){ //Log.Error("首字母化出错!"+e.Message); } return string.Empty; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值