会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
boytomato
汉字求出拼音缩写
using
System;
namespace
CsharpPinYing
{
/**/
///
///
PinYinClass 的摘要说明。
///
public
class
PinYinClass
{
public
PinYinClass()
{
//
//
TODO: 在此处添加构造函数逻辑
//
}
private
String PinYin(String mystr)
{
String tt;
if
((mystr.ToUpper().CompareTo(
"
A
"
)
>=
0
&&
mystr.ToUpper().CompareTo(
"
Z
"
)
<=
0
)
||
(mystr.ToUpper().CompareTo(
"
0
"
)
>=
0
&&
mystr.ToUpper().CompareTo(
"
9
"
)
<=
0
))
{
tt
=
mystr;
return
tt;
}
else
if
(Asc(mystr)
<
Asc(
"
啊
"
))
{
tt
=
"
1
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
啊
"
)
&&
Asc(mystr)
<
Asc(
"
芭
"
))
{
tt
=
"
a
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
芭
"
)
&&
Asc(mystr)
<
Asc(
"
擦
"
))
{
tt
=
"
b
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
擦
"
)
&&
Asc(mystr)
<
Asc(
"
搭
"
))
{
tt
=
"
c
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
搭
"
)
&&
Asc(mystr)
<
Asc(
"
蛾
"
))
{
tt
=
"
d
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
蛾
"
)
&&
Asc(mystr)
<
Asc(
"
发
"
))
{
tt
=
"
e
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
发
"
)
&&
Asc(mystr)
<
Asc(
"
噶
"
))
{
tt
=
"
f
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
噶
"
)
&&
Asc(mystr)
<
Asc(
"
哈
"
))
{
tt
=
"
g
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
哈
"
)
&&
Asc(mystr)
<
Asc(
"
击
"
))
{
tt
=
"
h
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
击
"
)
&&
Asc(mystr)
<
Asc(
"
喀
"
))
{
tt
=
"
j
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
喀
"
)
&&
Asc(mystr)
<
Asc(
"
垃
"
))
{
tt
=
"
k
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
垃
"
)
&&
Asc(mystr)
<
Asc(
"
妈
"
))
{
tt
=
"
l
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
妈
"
)
&&
Asc(mystr)
<
Asc(
"
拿
"
))
{
tt
=
"
m
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
拿
"
)
&&
Asc(mystr)
<
Asc(
"
哦
"
))
{
tt
=
"
n
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
哦
"
)
&&
Asc(mystr)
<
Asc(
"
啪
"
))
{
tt
=
"
o
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
啪
"
)
&&
Asc(mystr)
<
Asc(
"
期
"
))
{
tt
=
"
p
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
期
"
)
&&
Asc(mystr)
<
Asc(
"
然
"
))
{
tt
=
"
q
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
然
"
)
&&
Asc(mystr)
<
Asc(
"
撒
"
))
{
tt
=
"
r
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
撒
"
)
&&
Asc(mystr)
<
Asc(
"
塌
"
))
{
tt
=
"
s
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
塌
"
)
&&
Asc(mystr)
<
Asc(
"
挖
"
))
{
tt
=
"
t
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
挖
"
)
&&
Asc(mystr)
<
Asc(
"
昔
"
))
{
tt
=
"
w
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
昔
"
)
&&
Asc(mystr)
<
Asc(
"
压
"
))
{
tt
=
"
x
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
压
"
)
&&
Asc(mystr)
<
Asc(
"
匝
"
))
{
tt
=
"
y
"
;
return
tt;
}
else
if
(Asc(mystr)
>=
Asc(
"
匝
"
) )
{
tt
=
"
z
"
;
return
tt;
}
else
{
tt
=
mystr;
return
tt;
}
}
private
int
Asc(String Mystr)
{
int
inttemp;
byte
[] array
=
new
byte
[
2
];
array
=
System.Text.Encoding.Default.GetBytes(Mystr);
int
i1
=
(
short
)(array[
0
]
-
'
\0
'
);
int
i2
=
(
short
)(array[
1
]
-
'
\0
'
);
inttemp
=
Convert.ToInt32(i1.ToString()
+
i2.ToString());
return
inttemp;
}
public
String TransPinYin(String strInf)
{
String strTemp
=
""
;
int
iLength
=
strInf.Length;
for
(
int
i
=
0
;i
<=
iLength
-
1
;i
++
)
{
strTemp
+=
PinYin(strInf.Substring (i,
1
));
}
return
strTemp;
}
}
}
/**/
///////////////////////////
//
在程序中调用可用下面代码
private
void
button1_Click(
object
sender, System.EventArgs e)
{
PinYinClass py
=
new
PinYinClass();
textBox2.Text
=
py.TransPinYin(textBox1.Text);
}
/**/
/////////
/
当然现阶段求出的是小写,你也可转成大写
!
posted on
2005-03-02 08:33
gwazy
阅读(
727
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
导航
博客园
首页
新随笔
联系
订阅
管理
公告