zoukankan
html css js c++ java
获取中文首字母的方法
C#实现代码
public
class
Converter
{
static
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;
}
static
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
)(
97
+
i) }
);
}
}
return
"
*
"
;
}
else
return
cnChar;
}
}
查看全文
相关阅读:
window.location.href问题,点击,跳转到首页
JS indexOf() lastIndexOf()与substring()截取字符串的区别
原来的方法增加参数时,必须为新增的参数加个默认值
Chrome不支持本地Ajax请求解决?
Smarty中{literal}的使用详解
windows不能在本地计算机启动apache
Apache虚拟主机配置
wamp环境网站根目录更改
Java 读书笔记 (十三) for each 循环
Java 读书笔记 (十二) Java Character 类
原文地址:https://www.cnblogs.com/Randy0528/p/750605.html
最新文章
sublime中插件
Sublime text3
阴阳
javascript学习笔记2
javascript学习笔记1
javascript学习笔记
thinkphp之无限分类
thinkPHPbiji
c#导入文件以后查看制定值
项目管理【二】
热门文章
Liunx 简单的命令说明
Hadoop01的主要总结
01-VMware-workstation14安装
02-安装linux系统
山东省一个区和天津市一个区,名字一模一样!
数据单位
内存存储器和外存储器的异同
DOS命令
gitHub远程分支创建
脚本运行时间计算
Copyright © 2011-2022 走看看