예제 #1
0
        public static string GetInitials(string text)
        {
            text = text.Trim();
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < text.Length; i++)
            {
                string pinyin = Pinyin.GetPinyin(text[i]);
                if (pinyin != "")
                {
                    stringBuilder.Append(pinyin[0]);
                }
            }
            return(stringBuilder.ToString().ToUpper());
        }
예제 #2
0
        public static string GetPinyin(string text)
        {
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < text.Length; i++)
            {
                string pinyin = Pinyin.GetPinyin(text[i]);
                if (pinyin != "")
                {
                    stringBuilder.Append(pinyin);
                }
                stringBuilder.Append(" ");
            }
            return(stringBuilder.ToString().Trim());
        }
예제 #3
0
        public static void Main(string[] args)
        {
            string str;

            Console.WriteLine("--------------------  PinYin Test  --------------------");
            Console.WriteLine("说明:请输入要翻译的中文,示例如下。");
            Console.Write("->> ");
            Console.WriteLine(str = "中文翻译测试一下,效果如何?");
            Console.WriteLine($"    {Pinyin.GetInitials(str)} | {Pinyin.GetPinyin(str)}");
            Console.WriteLine();

readline:
            Console.Write("->> ");
            str = Console.ReadLine();

            if (str.ToLower() != "exit")
            {
                Console.WriteLine($"    {Pinyin.GetInitials(str)} | {Pinyin.GetPinyin(str)}");
                Console.WriteLine();
                goto readline;
            }
        }
예제 #4
0
 public static string GetPinyin(char ch, Encoding encoding)
 {
     ch = Pinyin.ConvertEncoding(ch.ToString(), encoding, Encoding.UTF8)[0];
     return(Pinyin.ConvertEncoding(Pinyin.GetPinyin(ch), Encoding.UTF8, encoding));
 }
예제 #5
0
        public static string GetPinyin(string text, Encoding encoding)
        {
            string text2 = Pinyin.ConvertEncoding(text.Trim(), encoding, Encoding.UTF8);

            return(Pinyin.ConvertEncoding(Pinyin.GetPinyin(text2), Encoding.UTF8, encoding));
        }