分享你我的心得.
共乘一片美好网络.

获取中文字符串拼音首字母串的函数

下面先是JS代码

<script language=vbs> 
function getpychar(char) 
tmp=65536+asc(char) 
if(tmp>=45217 and tmp<=45252) then 
getpychar= "A" 
elseif(tmp>=45253 and tmp<=45760) then 
getpychar= "B" 
elseif(tmp>=45761 and tmp<=46317) then 
getpychar= "C" 
elseif(tmp>=46318 and tmp<=46825) then 
getpychar= "D" 
elseif(tmp>=46826 and tmp<=47009) then 
getpychar= "E" 
elseif(tmp>=47010 and tmp<=47296) then 
getpychar= "F" 
elseif(tmp>=47297 and tmp<=47613) then 
getpychar= "G" 
elseif(tmp>=47614 and tmp<=48118) then 
getpychar= "H" 
elseif(tmp>=48119 and tmp<=49061) then 
getpychar= "J" 
elseif(tmp>=49062 and tmp<=49323) then 
getpychar= "K" 
elseif(tmp>=49324 and tmp<=49895) then 
getpychar= "L" 
elseif(tmp>=49896 and tmp<=50370) then 
getpychar= "M" 
elseif(tmp>=50371 and tmp<=50613) then 
getpychar= "N" 
elseif(tmp>=50614 and tmp<=50621) then 
getpychar= "O" 
elseif(tmp>=50622 and tmp<=50905) then 
getpychar= "P" 
elseif(tmp>=50906 and tmp<=51386) then 
getpychar= "Q" 
elseif(tmp>=51387 and tmp<=51445) then 
getpychar= "R" 
elseif(tmp>=51446 and tmp<=52217) then 
getpychar= "S" 
elseif(tmp>=52218 and tmp<=52697) then 
getpychar= "T" 
elseif(tmp>=52698 and tmp<=52979) then 
getpychar= "W" 
elseif(tmp>=52980 and tmp<=53640) then 
getpychar= "X" 
elseif(tmp>=53689 and tmp<=54480) then 
getpychar= "Y" 
elseif(tmp>=54481 and tmp<=62289) then 
getpychar= "Z" 
else '如果不是中文,则不处理 
getpychar=char 
end if 
end function 
function getpy(str) 
for i=1 to len(str) 
getpy=getpy&getpychar(mid(str,i,1)) 
next 
end function 

alert(cntext&"的首字母是:"&getpychar(cntext)) 
</script> 

下面是asp脚本

<%function getpychar(char)
dim tmpp:tmpp=65536+asc(char)
 if(tmpp>=45217 and tmpp<=45252) then 
getpychar= "A"
elseif(tmpp>=45253 and tmpp<=45760) then
getpychar= "B"
elseif(tmpp>=45761 and tmpp<=46317) then
getpychar= "C"
elseif(tmpp>=46318 and tmpp<=46825) then
getpychar= "D"
elseif(tmpp>=46826 and tmpp<=47009) then 
getpychar= "E"
elseif(tmpp>=47010 and tmpp<=47296) then 
getpychar= "F"
elseif(tmpp>=47297 and tmpp<=47613) then 
getpychar= "G"
elseif(tmpp>=47614 and tmpp<=48118) then
getpychar= "H"
elseif(tmpp>=48119 and tmpp<=49061) then
getpychar= "J"
elseif(tmpp>=49062 and tmpp<=49323) then 
getpychar= "K"
elseif(tmpp>=49324 and tmpp<=49895) then 
getpychar= "L"
elseif(tmpp>=49896 and tmpp<=50370) then 
getpychar= "M"
elseif(tmpp>=50371 and tmpp<=50613) then 
getpychar= "N"
elseif(tmpp>=50614 and tmpp<=50621) then 
getpychar= "O"
elseif(tmpp>=50622 and tmpp<=50905) then
getpychar= "P"
elseif(tmpp>=50906 and tmpp<=51386) then 
getpychar= "Q"
elseif(tmpp>=51387 and tmpp<=51445) then 
getpychar= "R"
elseif(tmpp>=51446 and tmpp<=52217) then 
getpychar= "S"
elseif(tmpp>=52218 and tmpp<=52697) then 
getpychar= "T"
elseif(tmpp>=52698 and tmpp<=52979) then 
getpychar= "W"
elseif(tmpp>=52980 and tmpp<=53640) then 
getpychar= "X"
elseif(tmpp>=53689 and tmpp<=54480) then 
getpychar= "Y"
elseif(tmpp>=54481 and tmpp<=62289) then
getpychar= "Z"
else '如果不是中文,则不处理
getpychar=char
end if
end function

function getpy(str)
for i=1 to len(str)
pystr=pystr & getpychar(mid(str,i,1))
next
getpy=lcase(pystr)
end function

zhoz_str = getpy(request.form("zhoz_txt"))
pingying = RTrim(zhoz_str)%>
赞(0)
未经允许不得转载:小叶白龙博客 » 获取中文字符串拼音首字母串的函数
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址