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;
}
}
查看全文
相关阅读:
HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
CSU 1120 病毒(DP)
CSU 1116 Kingdoms(枚举最小生成树)
一种map容器遍历的方法
CSU 1113 Updating a Dictionary(map容器应用)
Python模块-virtualenv-虚拟环境
计算学习原理
sklearn-特征工程之特征选择
链家网深圳租房信息分析报告
test
原文地址:https://www.cnblogs.com/Randy0528/p/750605.html
最新文章
指针和数组
指针系列——认识指针
组合模式
迭代器模式
模板模式
文件上传类配置
jquery Select2 学习笔记之中文提示
select2 如何自定义提示信息-布布扣-bubuko.com
windows下nginx配置报错GetFileAttributesEx
Ubuntu 安装 RabbitMQ 和PHP扩展
热门文章
TP5中隐藏入口文件的问题
Xdebug安装对应版本与配置
phpstorm调试环境XDebug搭建
phpstorm+xdebug详解
PhpStorm中如何配置SVN,详细操作方法
HDU 5073 Galaxy(2014鞍山赛区现场赛D题)
HDU 5074 Hatsune Miku(2014鞍山赛区现场赛E题)
HDU 5071 Chat(2014鞍山赛区现场赛B题)
CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)
PL/sql developer连接数据库的问题以及oracle数据库中文乱码的问题
Copyright © 2011-2022 走看看