今天看到xuejun的一个取汉字首字符的函数,试用了一下,感觉很好用,不敢独享,拿出来跟大家分享:
$PBExportHeader$uf_getfirstletter.srf
$PBExportComments$ 返回给定汉字串的首字母串, xuejun , 19990821
global type uf_getfirstletter from function_object
end type
forward prototypes
global function string uf_getfirstletter (string as_inputstring)
end prototypes
global function string uf_getfirstletter (string as_inputstring);//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"}</P><P> ls_SecondSecTable="CJWGNSPGCGNE[Y[BTYYZDXYKYGT[JNNJQMBSGZSCYJSYY[PGKBZGY[YWJKGKLJYWKPJQHY[W[DZLSGMRYPYWWCCKZNKYYGTTNJJNYKKZYTCJNMCYLQLYPYQFQRPZSLWBTGKJFYXJWZLTBNCXJJJJTXDTTSQZYCDXXHGCK[PHFFSS[YBGXLPPBYLL[HLXS[ZM[JHSOJNGHDZQYKLGJ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JYBZGDLQCSEZGXLBLGYXTWMABCHECMWYJYZLLJJYHLG[DJLSLYGKDZPZXJYYZLWCXSZFGWYYDLYHCLJSCMBJHBLYZLYCBLYDPDQYSXQZBYTDKYXJY[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 的声母串
end function
正在阅读:
2017计算机等考三级数据库基础:pb中取汉字串首字符的一个函数12-27
爸爸其实我懂你作文600字11-29
2018年湖北武汉大学单独选拔优秀人才攻读博士学位招生简章03-08
2018新疆妇产科主治医师报名入口已开通【报名时间:2017年12月28日至2018年1月19日】03-25
规则作文800字11-30
我心中的懊悔作文600字12-15
假如没有大人作文450字01-28
2023年下半年江西新余学业水平合格考网上缴费入口(10月9日开通)09-13
骑自行车作文400字08-05
关于小学生班级口号标语大全07-08
最美丽的风景作文600字06-17