Esempio n. 1
0
        /// <summary>
        /// 获取汉字首字母
        /// </summary>
        /// <param name="text">获取文本框数值</param>
        /// <param name="only">只返回汉字部分</param>
        /// <returns>返回每个汉字首字母</returns>
        public static string GetFirstPinYin(string text, bool only)
        {
            StringBuilder sb = new StringBuilder();

            foreach (char ch in text)
            {
                HanZi hz = Chinese.GetHanZi(ch);
                if (hz == null)
                {
                    if (only == false)
                    {
                        sb.Append(ch);
                    }
                }
                else
                {
                    sb.Append(hz.FirstPinYin);
                }
            }

            return(sb.ToString());
        }
Esempio n. 2
0
        protected HanziStrokeController()
        {
            HanziSvgTemplate = LoadTextFromResource("hanzi.svg");

            using (var stream = LoadStreamFromResource("all.txt"))
            {
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream))
                    {
                        string allZi = reader.ReadToEnd();
                        HanZi = NewtonJsonSerializer.ParseJSON <Dictionary <string, ChineseHanZi> >(allZi);
                    }
                }
            }

            using (var stream = LoadStreamFromResource("dictionary.txt"))
            {
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream))
                    {
                        while (!reader.EndOfStream)
                        {
                            string line  = reader.ReadLine();
                            var    hanzi = NewtonJsonSerializer.ParseJSON <ChineseHanZi>(line);
                            if (HanZi.ContainsKey(hanzi.character))
                            {
                                HanZi[hanzi.character].character     = hanzi.character;
                                HanZi[hanzi.character].decomposition = hanzi.decomposition;
                                HanZi[hanzi.character].definition    = hanzi.definition;
                                HanZi[hanzi.character].pinyin        = hanzi.pinyin;
                                HanZi[hanzi.character].radical       = hanzi.radical;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public int StrokeCount(string source)
 {
     return(HanZi.ContainsKey(source)?HanZi[source].strokes.Length:0);
 }