zoukankan      html  css  js  c++  java
  • 拼音检索

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

    我搜索到一个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();
            }
        }
    }

    感谢来访,共同学习!
  • 相关阅读:
    【XAF】非持久化对象分组和属于不同会话
    【原创】XAF 非持久对象界面中更新xpo的状态查询
    Java字符串操作方法集
    Java易忘知识点统计
    Android常用依赖库搜集
    Android Studio报错Unable to resolve dependency for ':app@release/compileClasspath':无法引用任何外部依赖的解决办法
    Codewars练习Python
    Python学习日记之正则表达式re模块
    Linux学习日记之crontab使用notify-send实现每小时通知提醒
    Linux学习日记之Deepin下查看crontab运行日志
  • 原文地址:https://www.cnblogs.com/dingxiaowei/p/3058762.html
Copyright © 2011-2022 走看看