我的取汉字首字母的算法存在什么问题?

menqqingling237 2003-03-24 04:59:07
总是取不处序号是偶数的汉字的首字母,为什么?

//xuejun, 19990821
//Function name : uf_GetFirstLetter
//Used to : 返回给定汉字串的首字母串,即声母串
//Input Arguments: as_InputString - string , 给定的汉字串
//Return Value : ls_ReturnString - String , 给定的汉字串的声母串,一律为小写
//Notice : 1. 此方法基于汉字的国标汉字库区位编码的有效性,不符合此编码的
// 系统此函数无效!
// 2. 若汉字串含有非汉字字符,如图形符号或ASCII码,则这些非汉字字符
// 将保持不变.
//Sample : ls_rtn = uf_GetFirstLetter("中华人民共和国")
// ls_rtn will be : zhrmghg

//Scripts:
char lc_FirstLetter[23] //存放国标一级汉字不同读音的起始区位码对应读音
string ls_ch //临时单元
string ls_SecondSecTable //存放所有国标二级汉字读音
string ls_ReturnStr //返回串
integer li_SecPosValue[23] //存放国标一级汉字不同读音的起始区位码
integer i , j
integer li_SectorCode //汉字区码
integer li_PositionCode //汉字位码
integer li_SecPosCode //汉字区位码
integer li_offset //二级字库偏移量

//Set initial value
li_SecPosValue[]={1601,1637,1833,2078,2274,2302,2433,2594,2787,3106,3212,3472,3635,3722,3730,3858,4027,4086,4390,4558,4684,4925,5249 }
lc_FirstLetter[] = {"A", "B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","R","S","T","W","X","Y","Z"}
ls_SecondSecTable="CJWGNSPGCGNE[Y[BTYYZDXYKYGT[JNNJQMBSGZSCYJSYY[PGKBZGY[YWJKGKLJYWKPJQHY[W[DZLSGMRYPYWWCCKZNKYYGTTNJJNYKKZYTCJNMCYLQLYPYQFQRPZSLWBTGKJFYXJWZLTBNCXJJJJTXDTTSQZYCDXXHGCK[PHFFSS[YBGXLPPBYLL[HLXS[ZM[JHSOJNGHDZQYKLGJHSGQZHXQGKEZZWYSCSCJXYEYXADZPMDSSMZJZQJYZC[J[WQJBYZPXGZNZCPWHKXHQKMWFBPBYDTJZZKQHYLYGXFPTYJYYZPSZLFCHMQSHGMXXSXJ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CNRJMPDJGKLCLJBCTBJDDBBLBLCZQRPPXJCJLZCSHLTOLJNMDDDLNGKAQHQHJGYKHEZNMSHRP[QQJCHGMFPRXHJGDYCHGHLYRZQLCYQJNZSQTKQJYMSZSWLCFQQQXYFGGYPTQWLMCRNFKKFSYYLQBMQAMMMYXCTPSHCPTXXZZSMPHPSHMCLMLDQFYQXSZYYDYJZZHQPDSZGLSTJBCKBXYQZJSGPSXQZQZRQTBDKYXZKHHGFLBCSMDLDGDZDBLZYYCXNNCSYBZBFGLZZXSWMSCCMQNJQSBDQSJTXXMBLTXZCLZSHZCXRQJGJYLXZFJPHYMZQQYDFQJJLZZNZJCDGZYGCTXMZYSCTLKPHTXHTLBJXJLXSCDQXCBBTJFQZFSLTJBTKQBXXJJLJCHCZDBZJDCZJDCPRNPQCJPFCZLCLZXZDMXMPHJSGZGSZZQLYLWTJPFSYASMCJBTZKYCWMYTCSJJLJCQLWZMALBXYFBPNLSFHTGJWEJJXXGLLJSTGSHJQLZFKCGNNNSZFDEQFHBSAQTGYLBXMMYGSZLDYDQMJJRGBJTKGDHGKBLQKBDMBYLXWCXYTTYBKMRTJZXQJBHLMHMJJZMQASLDCYXYQDLQCAFYWYXQHZ"

//Get it !
ls_ReturnStr = ""
For i=1 to Len(as_InputString) //依次处理as_InputString中每个字符
ls_ch=Mid(as_InputString , i , 1)
If Asc(ls_ch)<128 then // 非汉字
ls_returnStr = ls_returnStr+ls_ch // 不变
Else // 是汉字
ls_ch = Mid(as_InputString , i , 2) // 取出此汉字
li_SectorCode = Asc(Left(ls_ch, 1)) - 160 //区码
li_PositionCode = Asc(Right(ls_ch, 1)) - 160 //位码
li_SecPosCode = li_SectorCode*100 + li_PositionCode // 区位码
If li_SecPosCode>1600 and li_SecPosCode<5590 then // 第一个字符
For j=23 to 1 Step -1 // 找声母
If li_SecPosCode>=li_SecPosValue[j] then
ls_returnStr = ls_returnStr + lc_FirstLetter[j]
Exit
End if
Next
Else // 第一个字符
li_offset = (li_SectorCode - 56 ) *94 + li_PositionCode - 1 // 计算偏移量
If li_offset>=0 and li_offset<=3007 then //二区汉字
ls_returnStr = ls_returnStr + Mid(ls_SecondSecTable, li_offset , 1) //取出此字声母
End if
End if
i = i+1 // 指向下一个汉字
End if
Next // 处理完毕

//Return result
Return lower( ls_returnStr ) //返回 as_InputString 的声母串
...全文
72 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
fengzeng 2003-03-25
具体位置在:
http://www.hong-ao.com/liulee/share.php
回复
fengzeng 2003-03-25
http://www.hong-ao.com/liulee/share.php?action=show&threadid=82&s=0cfed09e495c98bf67c70fa0fe44793b
回复
fengzeng 2003-03-25
http://www.hong-ao.com/liulee/share.php?action=show&threadid=76&s=0cfed09e495c98bf67c70fa0fe44793b
回复
发帖
脚本语言
创建于2007-09-28

732

社区成员

PowerBuilder 脚本语言
申请成为版主
帖子事件
创建了帖子
2003-03-24 04:59
社区公告
暂无公告