日期:2014-05-17 浏览次数:20707 次
/// <summary> /// 得到每个汉字的字首拼音码字母(大写) /// </summary> /// <param name="chrStr">输入字符串</param> /// <returns>返回结果</returns> public string GetHeadCharacter(string chrStr) { string strHeadString = string.Empty; Encoding gb = System.Text.Encoding.GetEncoding("gb2312"); for (int i = 0; i < chrStr.Length; i++) { //检测该字符是否为汉字 if (!IsChineseCharacters(chrStr.Substring(i, 1))) { strHeadString += chrStr.Substring(i, 1); continue; } byte[] bytes = gb.GetBytes(chrStr.Substring(i, 1)); string lowCode = System.Convert.ToString(bytes[0] - 0xA0, 16); string hightCode = System.Convert.ToString(bytes[1] - 0xA0, 16); int nCode = Convert.ToUInt16(lowCode, 16) * 100 + Convert.ToUInt16(hightCode, 16); //得到区位码 strHeadString += FirstLetter(nCode); } return strHeadString; }