public static string GetPinYinFast(string text, bool tone = false) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.Length; i++) { var c = text[i]; sb.Append(PinYinDict.GetPinYinFast(c, tone ? 1 : 0)); } return(sb.ToString()); }
private void splitKeywords(string keyword, int baseIndex, List <string> results) { List <List <string> > ks = new List <List <string> >(); if (_type == PinYinSearchType.PinYin) { var pys = PinYinDict.GetPinYinList(keyword); for (int i = 0; i < keyword.Length; i++) { var list = new List <string>(); var t = keyword[i]; if ((t >= '0' && t <= '9') || (t >= 'A' && t <= 'Z')) { list.Add(t.ToString()); } else if (t >= 0x4e00 && t <= 0x9fa5) { var py = pys[i]; if (py == null) { py = " "; } //if (py == t.ToString()) py = " "; list.Add(py.ToUpper()); } else { list.Add(" "); } ks.Add(list); } } else { for (int i = 0; i < keyword.Length; i++) { var list = new List <string>(); var t = keyword[i]; if ((t >= '0' && t <= '9') || (t >= 'A' && t <= 'Z')) { list.Add(t.ToString()); } else if (t >= 0x4e00 && t <= 0x9fa5) { var pys = PinYinDict.GetAllPinYin(t); if (pys.Count == 0) { pys.Add(" "); } foreach (var item in pys) { list.Add(item.ToUpper()); } } else { list.Add(" "); } ks.Add(list); } } foreach (var item in ks[0]) { var py = item[0].ToString() + pinYinSpace + item + pinYinSpace + keyword[0]; splitKeywords(py, 1, ks, keyword, baseIndex, results); } }
private bool trySplitSearchText(string text, out TextLine root) { text = text.ToUpper(); var rs = getPinYinSplit().FindAll(text); root = new TextLine(); List <TextLine> textLines = new List <TextLine>() { root }; #region 初始化 TextLine for (int i = 0; i < text.Length; i++) { var c = text[i]; if (_type == PinYinSearchType.PinYin && c >= 0x4e00 && c <= 0x9fa5) { var pys = PinYinDict.GetAllPinYin(c); if (pys.Count == 0) { pys.Add(" "); } for (int j = 0; j < pys.Count; j++) { var py = pys[j].ToUpper(); TextLine tl;// = new TextLine(); if (j == 0) { tl = new TextLine(py[0], py, c); textLines.Add(tl); } else { tl = new TextLine(py[0], py, c, textLines[i + 1]); } textLines[i].Add(tl); } } else { TextLine tl; if (c >= 0x4e00 && c <= 0x9fa5) { var py = PinYinDict.GetPinYinFast(c); tl = new TextLine(py[0], py, c); } else if (c >= '0' || c <= '9') { tl = new TextLine(c, null, (char)0); } else if (c >= 'A' || c <= 'Z') { tl = new TextLine(c, null, (char)0); } else { tl = new TextLine(' ', " ", c); } textLines[i].Add(tl); textLines.Add(tl); } } #endregion #region 划分拼音 foreach (var r in rs) { var tl2 = new TextLine(r.Keyword[0], r.Keyword, (char)0, textLines[r.End + 1]); textLines[r.Start].Add(tl2); } #endregion return(true); }
/// <summary> /// 获取姓名拼音,中文字符集为[0x3400,0x9FD5],注:偏僻汉字很多未验证 /// </summary> /// <param name="name">姓名</param> /// <param name="tone">是否带声调</param> /// <returns></returns> public static List <string> GetPinYinListForName(string name, bool tone = false) { return(PinYinDict.GetPinYinForName(name, tone ? 1 : 0)); }
/// <summary> /// 获取姓名拼音,中文字符集为[0x3400,0x9FD5],注:偏僻汉字很多未验证 /// </summary> /// <param name="name">姓名</param> /// <param name="tone">是否带声调</param> /// <returns></returns> public static string GetPinYinForName(string name, bool tone = false) { return(string.Join("", PinYinDict.GetPinYinForName(name, tone ? 1 : 0))); }
/// <summary> /// 获取所有拼音,中文字符集为[0x3400,0x9FD5],注:偏僻汉字很多未验证 /// </summary> /// <param name="c">原文本</param> /// <param name="tone">是否带声调</param> /// <returns></returns> public static List <string> GetAllPinYin(char c, bool tone = false) { return(PinYinDict.GetAllPinYin(c, tone ? 1 : 0)); }
/// <summary> /// 获取拼音全拼,支持多音,中文字符集为[0x4E00,0x9FD5] /// </summary> /// <param name="text">原文本</param> /// <param name="tone">是否带声调</param> /// <returns></returns> public static string GetPinYin(string text, bool tone = false) { return(PinYinDict.GetPinYin(text, tone ? 1 : 0)); }
/// <summary> /// 获取首字母,中文字符集为[0x3400,0x9FD5],注:偏僻汉字很多未验证 /// </summary> /// <param name="text">原文本</param> /// <returns></returns> public static string GetFirstPinYin(string text) { return(PinYinDict.GetFirstPinYin(text, 0)); }
/// <summary> /// 获取所有拼音 /// </summary> /// <param name="s"></param> /// <returns></returns> public static List <string> GetAllPinYin(char s) { return(PinYinDict.GetAllPinYin(s)); }
/// <summary> /// 获取拼音全拼,支持多音,中文字符集为[0x4E00,0x9FA5] /// </summary> /// <param name="text"></param> /// <returns></returns> public static string GetPinYin(string text, bool isEmpty = false) { return(PinYinDict.GetPinYin(text, isEmpty)); }