/// <summary> /// 取单个汉字的拼音首字母 /// </summary> /// <param name="strName">汉字字符串。如果输入多个汉字,只取第一个汉字的拼音首字母</param> /// <returns>第一个拼音字母</returns> public static char GetFirstPyChar(string strName) { char result; if (!string.IsNullOrEmpty(strName)) { result = Chs2py.GetFirstPyChar(strName[0]); } else { result = ' '; } return(result); }
/// <summary> /// 取字符串中每个汉字的拼音首写 /// </summary> /// <param name="strName"></param> /// <returns></returns> public static string GetFirstPyString(string strName) { string py = string.Empty; if (!string.IsNullOrEmpty(strName)) { for (int i = 0; i < strName.Length; i++) { char item = strName[i]; py += Chs2py.GetFirstPyChar(item).ToString(); } } return(py.ToLower()); }
/// <summary> /// 取单个汉字的拼音首字母 /// </summary> /// <param name="c">单个汉字</param> /// <returns>第一个拼音字母</returns> public static char GetFirstPyChar(char c) { string pinyin = Chs2py.GetFullChs2Py(c.ToString()); char result; if (!string.IsNullOrEmpty(pinyin)) { result = pinyin.ToUpper()[0]; } else { result = ' '; } return(result); }
/// <summary> /// 取汉字的Unicode编码 /// </summary> /// <param name="c"></param> /// <returns></returns> public static short GetGB2312Code(char c) { return(Chs2py.GetGB2312Code(string.Concat(c))); }