Esempio n. 1
0
        public void CodingString(WordLibrary wl, IWordCodeGenerater factory)
        {
            var codes = new List <string>();

            foreach (char c in wl.Word)
            {
                string code = factory.GetCodeOfChar(c);
                codes.Add(code);
            }
            wl.PinYin = codes.ToArray();
        }
Esempio n. 2
0
        public WordLibraryList ImportLine(string word)
        {
            string hz = "";
            var    py = new List <string>();
            int    j;

            for (j = 0; j < word.Length - 1; j++)
            {
                hz += word[j];
                if (word[j + 1] > 'z') //而且后面跟的不是拼音
                {
                    py.Add(single.GetCodeOfChar(word[j]));
                }
                else //后面跟拼音
                {
                    int    k   = 1;
                    string py1 = "";
                    while (j + k != word.Length && word[j + k] <= 'z')
                    {
                        py1 += word[j + k];
                        k++;
                    }
                    py.Add(py1);
                    j += k - 1; //减1是因为接下来会运行j++
                }
            }
            if (j == word.Length - 1) //最后一个字是汉字
            {
                hz += word[j];
                py.Add(single.GetCodeOfChar(word[j]));
            }
            var wl = new WordLibrary();

            wl.PinYin = py.ToArray();
            wl.Word   = hz;
            var wll = new WordLibraryList();

            wll.Add(wl);
            return(wll);
        }
Esempio n. 3
0
 public void CodingString(WordLibrary wl, IWordCodeGenerater factory)
 {
     var codes = new List<string>();
     foreach (char c in wl.Word)
     {
         string code = factory.GetCodeOfChar(c);
         codes.Add(code);
     }
     wl.PinYin = codes.ToArray();
 }