ASP.NET获取汉字首字母
2015-02-04 22:39
309 查看
/// <summary> /// 获取汉字首字母(可包含多个汉字) /// </summary> /// <param name="strText"></param> /// <returns></returns> public string GetChineseSpell(string strText) { int len = strText.Length; string myStr = ""; for (int i = 0; i < len; i++) { myStr += getSpell(strText.Substring(i, 1)); } return myStr; } public string getSpell(string cnChar) { byte[] arrCN = Encoding.Default.GetBytes(cnChar); if (arrCN.Length > 1) { int area = (short)arrCN[0]; int pos = (short)arrCN[1]; int code = (area << 8) + pos; int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 }; for (int i = 0; i < 26; i++) { int max = 55290; if (i != 25) max = areacode[i + 1]; if (areacode[i] <= code && code < max) { return Encoding.Default.GetString(new byte[] { (byte)(65 + i) }); } } return "*"; } else return cnChar; } =============================================================================================== /// <summary> /// 获取第一个汉字的首字母,只能输入汉字 /// </summary> /// <param name="c"></param> /// <returns></returns> public string GetPYChar(string c) { byte[] array = new byte[2]; array = System.Text.Encoding.Default.GetBytes(c); int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0')); if (i < 0xB0A1) return "*"; if (i < 0xB0C5) return "A"; if (i < 0xB2C1) return "B"; if (i < 0xB4EE) return "C"; if (i < 0xB6EA) return "D"; if (i < 0xB7A2) return "E"; if (i < 0xB8C1) return "F"; if (i < 0xB9FE) return "G"; if (i < 0xBBF7) return "H"; if (i < 0xBFA6) return "J"; if (i < 0xC0AC) return "K"; if (i < 0xC2E8) return "L"; if (i < 0xC4C3) return "M"; if (i < 0xC5B6) return "N"; if (i < 0xC5BE) return "O"; if (i < 0xC6DA) return "P"; if (i < 0xC8BB) return "Q"; if (i < 0xC8F6) return "R"; if (i < 0xCBFA) return "S"; if (i < 0xCDDA) return "T"; if (i < 0xCEF4) return "W"; if (i < 0xD1B9) return "X"; if (i < 0xD4D1) return "Y"; if (i < 0xD7FA) return "Z"; return "*"; }
相关文章推荐
- asp.net 获取汉字首字母
- asp.net汉字转拼音和获取汉字首字母的代码
- asp.net汉字转拼音和获取汉字首字母的代码
- asp.net汉字转拼音和获取汉字首字母的代码
- ASP.NET获取汉字拼音的首字母
- ASP.NET获取汉字拼音的首字母
- ASP.NET 根据汉字获取汉字拼音的首字母(含多音字)
- ASP.NET获取汉字拼音的首字母
- ASP.NET获取汉字拼音的首字母
- asp.net获取中文汉字的首字母
- ASP.NET获取汉字首字母
- asp.net汉字转拼音和获取汉字首字母的代码
- ASP.NET 根据汉字获取汉字拼音的首字母(含多音字)
- [Asp.Net WinForm]利用Visual Studio International Pack来获取汉字的拼音缩写
- vb.net 获取汉字首字母的办法
- asp.net 汉字转换拼音及首字母实现代码
- asp输入汉字获取汉字的首字母收藏
- asp.net汉字转拼音 可返回拼音首字母
- asp.net 根据汉字的拼音首字母搜索数据库(附 LINQ 调用方法)
- C# Asp.net生成字母或汉字验证码,可自定义验证码控件