2009年3月31日,微软发布了 Microsoft Visual Studio International Pack 1.0 SR1。Visual Studio International Pack 包含一组类库,该类库扩展了.NET Framework对全球化软件开发的支持。使用该类库提供的类,.NET 开发人员可以更方便的创建支持多文化多语言的软件应用。下载地址是:http://www.microsoft.com/downloads/details.aspx?FamilyID=44cac7f0-633b-477d-aed2-99aee642fc10&DisplayLang=zh-cn 该软件包1.0版提供下面七个组件以增强.NET Framework对全球化软件应用开发的支持。
下载完毕后,进行解压,里面有7个msi文件,其中:CHSPinYinConv.msi就是汉字拼音相关的,CHTCHSConv.msi是进行简体与繁体进行相互转换的,值安装这2个msi即可。安装完毕后,需要在VS里添加引用,分别引用:C:/Program Files/Microsoft Visual Studio International Pack/Simplified Chinese Pin-Yin Conversion Library下和C:/Program Files/Microsoft Visual Studio International Pack/Traditional Chinese to Simplified Chinese Conversion Library and Add-In Tool下的dll即可使用。下面是一个汉字“孟”的测试例子:
C# 代码
using System;
using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.International.Converters.PinYinConverter; using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter; using System.Collections.ObjectModel; public partial class Default2 : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { ChineseChar chineseChar = new ChineseChar( ' 孟 '); Response.Write( " <h2>关于汉字 “孟” 的相关信息:</h2> "); Response.Write( " <li>“孟”笔画数: " + ChineseChar.GetStrokeNumber( ' 孟 ')); Response.Write( " <li>“孟”是否是多音字: " + chineseChar.IsPolyphone); ReadOnlyCollection< string> pinyin = chineseChar.Pinyins; Response.Write( " <li>“孟”所有拼音: "); foreach ( string pin in pinyin) { Response.Write(pin + " , "); } char[] ChineseChars; Response.Write( " <li>所有拼音 MENG1 的汉字<br/> "); ChineseChars = ChineseChar.GetChars( " MENG1 "); Response.Write( " 共 " + ChineseChars.Length.ToString() + " 个,分别是: "); for ( int i = 0; i < ChineseChars.Length; i++) { Response.Write(ChineseChars[i] + " , "); } Response.Write( " <li>所有拼音 MENG2 的汉字 <br/> "); ChineseChars = ChineseChar.GetChars( " MENG2 "); Response.Write( " 共 " + ChineseChars.Length.ToString() + " 个,分别是: "); for ( int i = 0; i < ChineseChars.Length; i++) { Response.Write(ChineseChars[i]); } Response.Write( " <li>所有拼音 MENG3 的汉字<br/> "); ChineseChars = ChineseChar.GetChars( " MENG3 "); Response.Write( " 共 " + ChineseChars.Length.ToString() + " 个,分别是: "); for ( int i = 0; i < ChineseChars.Length; i++) { Response.Write(ChineseChars[i]); } Response.Write( " <li>所有拼音 MENG2 的汉字<br/> "); ChineseChars = ChineseChar.GetChars( " MENG4 "); Response.Write( " 共 " + ChineseChars.Length.ToString() + " 个,分别是: "); for ( int i = 0; i < ChineseChars.Length; i++) { Response.Write(ChineseChars[i]); } Response.Write( " <li>所有拼音 MENG5 的汉字<br/> "); ChineseChars = ChineseChar.GetChars( " MENG5 "); Response.Write( " 共 " + ChineseChars.Length.ToString() + " 个,分别是: "); for ( int i = 0; i < ChineseChars.Length; i++) { Response.Write(ChineseChars[i]); } String simText = " 欢迎光临【孟子E章】 "; String traText = ChineseConverter.Convert(simText, ChineseConversionDirection.SimplifiedToTraditional); Response.Write( " <li>繁简转换测试: " + traText); } }
得到的结果是: 关于汉字 “孟” 的相关信息:
不过:有几个方面主要注意:
中文简体与中文繁体之间的转换比较简单,下面就是一个将简体转换成繁体的代码:
C# 代码
String simText =
"
欢迎光临【孟子E章】
";
String traText = ChineseConverter.Convert(simText, ChineseConversionDirection.SimplifiedToTraditional); Response.Write( " <li>繁简转换测试: " + traText);
下面是Microsoft.International.Converters.PinYinConverter.ChineseChar类的成员: 封装了简体中文的读音和笔画等基本信息。
其他信息请参与随机安装的chm帮助文件。 |
微软类库 中文(汉语)转拼音
最新推荐文章于 2023-01-05 00:37:53 发布