Esempio n. 1
0
        /// <summary>
        /// 获取首字母
        /// </summary>
        /// <param name="ChineseCharacter">字符串</param>
        /// <returns></returns>
        public static string GetFullLetterSpell(string ChineseCharacter)
        {
            var resFull = new List <List <string> >();

            //获取每个汉字的全拼和首字母列表(一个字一行)
            foreach (var item in ChineseCharacter)
            {
                HanZi hz = null;
                if (HanziDict.TryGetValue(item, out hz))
                {
                    var temp = hz.PinyinIndexList.Select(c => PinYinDict[c][0].ToString()).ToList();//取首字母
                    resFull.Add(temp);
                }
                else
                {
                    resFull.Add(new List <string> {
                        item.ToString().ToUpper()
                    });
                }
            }

            var fullList = CombineResult(resFull);
            var fullStr  = "";

            fullList.ForEach(c => fullStr = fullStr + c + CombineSign);
            return(fullStr.TrimEnd(CombineSign[0]));
        }
Esempio n. 2
0
 /// <summary>
 /// 使用HanZiDictionary原始文件进行创建字典HanziDict
 /// </summary>
 private static void InitHanzi()
 {
     try
     {
         Assembly assembly = typeof(ChineseCharToPinYinHelper).Assembly;
         using (BinaryReader binaryReader = new BinaryReader(assembly.GetManifestResourceStream("HanZiPinYin.Files.HanZiDictionary")))
         {
             // binaryReader.ReadInt32();
             binaryReader.ReadInt32();
             var count = binaryReader.ReadInt32();
             binaryReader.ReadInt16();
             binaryReader.ReadBytes(24);
             for (int index = 0; index < count; ++index)
             {
                 var hanzi = new HanZi()
                 {
                     Char         = binaryReader.ReadChar(),
                     StrokeNumber = binaryReader.ReadByte(),
                     PinyinCount  = binaryReader.ReadByte()
                 };
                 hanzi.PinyinIndexList = new short[(int)hanzi.PinyinCount];
                 for (int i = 0; i < (int)hanzi.PinyinCount; ++i)
                 {
                     hanzi.PinyinIndexList[i] = binaryReader.ReadInt16();
                 }
                 HanziDict.Add(hanzi.Char, hanzi);
             }
         }
     }
     catch (Exception ex)
     {
     }
 }