获取中文字符串的首字母
来源:互联网 发布:公司网络屏蔽淘宝 编辑:程序博客网 时间:2024/06/02 21:50
/// <summary>
/// 获取中文字符串的首字母
/// </summary>
/// <param name="strText"></param>
/// <returns></returns>
public static 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;
}
/// <summary>
/// 获取单个中文的首字母
/// </summary>
/// <param name="cnChar"></param>
/// <returns></returns>
private static 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)(97 + i) });
}
}
return "*";
}
else return cnChar;
}
- 获取中文字符串的首字母
- 获取中文字符串拼音首字母
- php 获取中文字符串首字母
- PHP获取字符串的第一个中文的首字母
- 获取中文字符串拼音首字母串的函数
- 【代码】php 中文字符串首字母函数的获取
- 字符串获取字符串的首字母
- 获取中文首字母的方法
- 获取中文汉字的首字母
- SQLServer 2008 创建获取中文字符串首字母
- ORACLE获取中文字符串拼音首字母
- js 获取中文字符串首字母 兼容英文字符串
- 获取中文拼音的首字母的方法
- -asp网站的按字母查询- [JS] 获取中文字符串拼音首字母串的函数
- 获取字符串的每个中文字符拼音首字母的ASP函数
- c#获取中文首字母的方法
- C# 获取中文的拼音首字母
- 获取中文拼音首字母的SQL函数
- 存储过程varchar与int的连接
- Yii使用中找不到yiic问题
- 解决 /etc/postfix/main.cf: No such file or directory
- Linux下:分区及格式化命令
- 嘿嘿,Real6410/TE6410/OK6410 支持jlink V8+RVDS2.2 仿真调试了
- 获取中文字符串的首字母
- 解析网卡配置静态Ubuntu IP地址
- ASP.NET网站权限设计实现(一)——使用PowerDesigner进行数据库设计
- 自删除技术 (网上收集加理解)
- OSPF协议介绍
- hadoop学习(五)
- C核心技术手册(二十四)
- C语言的谜题
- 不开心