有懂VB的C#大虾没,帮忙把这个生成拼音码的方法转成C#下吧,小女万分感谢.

zouchun_donet 2012-05-04 01:15:45
long length_string,step_string,asc_char,i
string pym_string,pym,char_string
// 取得字符串长度
length_string = len(hz_cluster)
// 设定初始值
i = 1
pym_string = ' '
do until i > length_string
char_string = mid(hz_cluster,i,1)
asc_char = asc(char_string)
// 设定默认步长
step_string = 1
if asc_char > 64 and asc_char < 91 then // 大写字母
pym = char_string
elseif asc_char > 96 and asc_char < 123 then // 小写字母
pym = char_string
elseif asc_char > 47 and asc_char < 58 then // 数字
pym = char_string
elseif asc_char > 127 then // 汉字,步长为2
char_string = mid(hz_cluster,i,2)
select pym into :pym from sys_hzk where hz=:char_string;
If Sqlca.sqlcode <> 0 Then pym = '* '
pym = mid(pym,1,1)
step_string = 2
else // 其它字符
pym = ' '
end if
i = i + step_string
pym_string = pym_string + pym
loop
// 以小写方式返回
return left(upper(pym_string),12)
...全文
145 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
zouchun_donet 2012-05-11
  • 打赏
  • 举报
回复

[Quote=引用 11 楼 的回复:]
C# code



public static string getPYM(string hz_cluster)
{
int length_string = 0;
string pym_string = string.Empty, pym = string.Empty;
ch……
[/Quote]


结贴了,这是最终测试过的code..
zouchun_donet 2012-05-11
  • 打赏
  • 举报
回复


public static string getPYM(string hz_cluster)
{
int length_string = 0;
string pym_string = string.Empty, pym = string.Empty;
char char_string = ' ';
// 取得字符串长度
length_string = hz_cluster.Length;
// 设定初始值
int i = 0;
int asc_char;
while (i < length_string)
{
char_string = hz_cluster.Substring(i, 1)[0];
asc_char = Convert.ToInt32(char_string);
if ((asc_char > 64) && (asc_char < 91))// 大写字母
{
pym = char_string.ToString();
}
else if ((asc_char > 96) && (asc_char < 123)) // 小写字母
{
pym = char_string.ToString();
}
else if ((asc_char > 47) && (asc_char < 58)) // 数字
{
pym = char_string.ToString();
}
else if (asc_char > 127) // 汉字
{
pym = GetOnePYM(hz_cluster.Substring(i, 1));
}
else
{// 其它字符
pym = "*";
}
i += 1;
pym_string = pym_string + pym;
}
// 以大写方式返回
return pym_string.ToUpper();
}


public static string GetOnePYM(string hz)
{
return DBHelper.ExecuteScalar("select isnull(pym,'*') from sys_hzk where hz=@hz"
, new SqlParameter[] { new SqlParameter("@hz", hz) }).ToString();
}
anzhiqiang_touzi 2012-05-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
用在线 VB 转 C# 的:
http://codechanger.com/
[/Quote]http://codechanger.com/rum/ui/scripts/csdn/Plugin/001/face/79.gif" alt="" />

sunylf 2012-05-04
  • 打赏
  • 举报
回复
這個很簡單的吧.
mbtw_1984 2012-05-04
  • 打赏
  • 举报
回复
用在线 VB 转 C# 的:
http://codechanger.com/
  • 打赏
  • 举报
回复
如果是汉字转拼音的话可以给你发个做好的程序看看
zouchun_donet 2012-05-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
google+baidu+msdn,自己花时间学到知识才能记忆深刻。
[/Quote]



介个,懂~
但是这个只是供我调用的一个方法之一,等我学到这些,项目的进度就...
test2050 2012-05-04
  • 打赏
  • 举报
回复
google+baidu+msdn,自己花时间学到知识才能记忆深刻。
bdmh 2012-05-04
  • 打赏
  • 举报
回复
去看帮助
zouchun_donet 2012-05-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
mid -> sustring
asc -> convert.toint32

left -> sustring

其他的不用说了吧,就这么几个方法在里面
[/Quote]


能详尽点么?
bdmh 2012-05-04
  • 打赏
  • 举报
回复
mid -> sustring
asc -> convert.toint32

left -> sustring

其他的不用说了吧,就这么几个方法在里面

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧