您的位置:首页 > 其它

使用微软语言包实现汉字转拼音

2014-05-16 18:12 375 查看
网上有很多汉字转拼音的方案,但并不知道性能和可靠性如何。所以本着选择权威的原则,还是想找一个官方的解决方案。下面实用微软官方的语言包实现汉字转拼音。

下载地址:http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=44cac7f0-633b-477d-aed2-99aee642fc10&DisplayLang=zh-cn

此安装包包含日语、汉语、韩语等多种语言,选择安装CHSPinYinConv.msi。完成之后在项目中引用安装目录中的ChnCharInfo.dll即可。

下面就是实现汉字转拼音的demo

using Microsoft.International.Converters.PinYinConverter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Suspects.Dll.Util
{
    publicclassPinYinUtil
    {
        //返回字符串的简拼
        publicstaticstring getSimplePinYin(stringinputTxt)
        {
            string shortR ="";
            foreach (char cin inputTxt.Trim())
            {
                ChineseChar chineseChar =newChineseChar(c);
                shortR +=chineseChar.Pinyins[0].Substring(0, 1).ToLower();
            }
            return shortR;
        }
 
        //返回字符串全拼
        publicstaticstring getAllPinYin(string inputTxt)
        {
            string allR ="";
            foreach (char cin inputTxt.Trim())
            {
                ChineseChar chineseChar =newChineseChar(c);
                allR += chineseChar.Pinyins[0].Substring(0,chineseChar.Pinyins[0].Length - 1).ToLower();
            }
            return allR;
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐