添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《 阿里云开发者社区用户服务协议 》和 《 阿里云开发者社区知识产权保护指引 》。如果您发现本社区中有涉嫌抄袭的内容,填写 侵权投诉表单 进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

当我们遇到要处理汉字和拼音之间的转化关系怎么办?如和用程序来实现?

我搜索到一个ChineseChar开发包,然后实现了这一难题

using System;
using Microsoft.International.Converters.PinYinConverter;

namespace 拼音基础
{
class Program
{
static void Main(string[] args)
{

#region 判断是否为同音字
ChineseChar chineseChar = new ChineseChar('微');
Console.WriteLine("Stroke number of 微 in Chinese is {0}.", chineseChar.StrokeNumber);
Console.WriteLine("{0} characters' pinyin is \"wei1\".", ChineseChar.GetHomophoneCount("wei1"));
if (ChineseChar.IsHomophone('微', '薇'))
{
Console.WriteLine("微 and 薇 have the same pinyin.");
}
else
{
Console.WriteLine("微 and 薇 have different pinyins.");
}
#endregion
ChineseChar char1 = new ChineseChar('单');
bool f = ChineseChar.IsHomophone('杨','洋');
Console.Write("杨和洋是否为同音字"+f);
Console.Write("\n单是否为多音字:"+char1.IsPolyphone);
char[] chars = ChineseChar.GetChars("ji3");//要加上声调
foreach (char c in chars)
{
Console.Write(c + " ");
}

for (int i = 0; i < char1.PinyinCount; i++)
{
string s=char1.Pinyins[i];
Console.WriteLine(s);
}


//判断是否是一个拼音字符串
Console.WriteLine("de是否是一个合法的拼音"+ChineseChar.IsValidPinyin("de1"));//1,2,3,4表示声调

#region 输入一段中文,写出拼音
string str = Console.ReadLine();
foreach (char c in str)
{
if (ChineseChar.IsValidChar(c))
{
ChineseChar cc = new ChineseChar(c);
Console.Write(cc.Pinyins[0] + " ");
}
else
{
Console.Write(c);
}
}
#endregion

Console.Read();
}
}
}