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;
}
}
查看全文
相关阅读:
day 1 认识js
day2,request对象
day3
day 14 函数的嵌套,作用域
命名空间(名称空间)
day 13 函数
day 11(2) 集合
day 11 字典拆包
字典
两周英语函数(记)
原文地址:https://www.cnblogs.com/Randy0528/p/750605.html
最新文章
colletion知识点之集合的遍历(转数组遍历研究)
collection知识点2
collection集合知识点
python基础补充(2)
python基础补充
linux数据库2
liunx数据库
python(字典)
python(元组)
python(列表)
热门文章
python第七课
python(if判断和for循环)
python(while循环)
进程
创建进程(函数)
守护进程
锁 Lock
事件 (控制进程执行还是阻塞的一个机制)Event
队列 Queue(可以设置队列元素数量)
操作系统认识
Copyright © 2011-2022 走看看