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(); }
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)); //string label = slg.Lookup(keySelector(item)); index = list.FindIndex(alphaKeyGroup => (alphaKeyGroup.Key.Equals(label, StringComparison.CurrentCulture))); } if (index >= 0 && index < list.Count) { list[index].InternalList.Add(item); } else { //临时解决方案,中文加入??中 list[list.Count - 1].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); }