예제 #1
0
        public static string GetPinyin(string str)
        {
            StringBuilder rtnSb = new StringBuilder("");

            char[] charary = str.ToCharArray();
            for (int i = 0; i < charary.Length; i++)
            {
                var ch = charary[i];
                if (ChineseHelper.IsCharChinese(ch))
                {
                    for (int j = 0; j < _Allhz.Length; j++)
                    {
                        if (_Allhz[j][1].IndexOf(ch) != -1)
                        {
                            rtnSb.Append(_Allhz[j][0]);
                            break;
                        }
                    }
                }
                else
                {
                    rtnSb.Append(ch);
                }
            }
            return(rtnSb.ToString());
        }
예제 #2
0
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, Func <T, string> keySelector, bool sort)
        {
            CharacterGroupings slg = new CharacterGroupings();
            //List<AlphaKeyGroup<T>> list = CreateDefaultGroups(slg);
            List <AlphaKeyGroup <T> > list = CreateAZGroups();

            foreach (T item in items)
            {
                int      index = 0;
                string[] label = ChineseHelper.GetFirstWord(keySelector(item));
                for (int i = 0; i < label.Length; i++)
                {
                    string lableKey = label[i];
                    index = list.FindIndex(alphaKeyGroup => (alphaKeyGroup.Key.Equals(lableKey, StringComparison.CurrentCulture)));
                    list[index].InternalList.Add(item);
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.InternalList.Sort((c0, c1) => { return(keySelector(c0).CompareTo(keySelector(c1))); });
                    //group.InternalList = group.InternalList.OrderBy(r => {  return r.WebSite; });
                }
            }

            return(list);
        }