Ejemplo n.º 1
0
        public static string GetPinyin(char ch)
        {
            short hashIndex = Pinyin.GetHashIndex(ch);

            for (int i = 0; i < PyHash.hashes[(int)hashIndex].Length; i++)
            {
                short num  = PyHash.hashes[(int)hashIndex][i];
                int   num2 = PyCode.codes[(int)num].IndexOf(ch, 7);
                if (num2 != -1)
                {
                    return(PyCode.codes[(int)num].Substring(0, 6).Trim());
                }
            }
            return(ch.ToString());
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
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());
        }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
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));
 }
Ejemplo n.º 6
0
        public static string GetChineseText(string pinyin, Encoding encoding)
        {
            string pinyin2 = Pinyin.ConvertEncoding(pinyin, encoding, Encoding.UTF8);

            return(Pinyin.ConvertEncoding(Pinyin.GetChineseText(pinyin2), Encoding.UTF8, encoding));
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public static string GetInitials(string text, Encoding encoding)
        {
            string text2 = Pinyin.ConvertEncoding(text, encoding, Encoding.UTF8);

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