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;
}
}
查看全文
相关阅读:
多个tomcat配置,解决冲突问题
多态-重载和覆载
静态成员、静态类和枚举
重复使用类--继承和组合
建立更可靠的OOP程序-类和成员的访问控制
用ps画一个Gif的小房子(1)
在h5页面上添加音乐播放
使用Object类为实例定义方法和属性
使用 prototype 定义方法和属性
使用 this 关键字定义方法和属性
原文地址:https://www.cnblogs.com/Randy0528/p/750605.html
最新文章
专题:CF图论杂题
python- 属性 静态方法,类方法
Python- 接口类-抽象类
Python-面向对象-继承
python_面向对象,类名称空间,对象名称空间,组合
Python-初识面向对象
二分查找算法
递归函数
python-内置函数,匿名函数
Python-02 生成器表达式,列表推导式
热门文章
python-迭代器,生成器
Memcached 与 Redis 的关键性能指标比较
nfs server and client
nginx 集群简述
zookeeper 原理
linux常用系统命令
mysql5.7 设置密码
Tomcat web deploy
本地sql文件导入mysql数据库
Gitlab 灾备措施
Copyright © 2011-2022 走看看