我想在表单中输入一行文字,点击"提交"后,在该页或某页中输入该文字的拼音简码
例:输入"早上好"
输出"ZSH"
不知道能不能实现这样的功能,请教请教
<%
'返回汉字拼音首字母串
Function getpychar(char)
getpychar = ""
Dim charLen,chrInt,tmpp,pychar
charLen = Len(char)
If charLen < 1 Then Exit Function
For chrInt = 1 To charLen
tmpp=65536+asc(Mid(char,chrInt,1))
If(tmpp>=45217 And tmpp<=45252) Then
pychar= "A"
ElseIf(tmpp>=45253 And tmpp<=45760) Then
pychar= "B"
ElseIf(tmpp>=45761 And tmpp<=46317) Then
pychar= "C"
ElseIf(tmpp>=46318 And tmpp<=46825) Then
pychar= "D"
ElseIf(tmpp>=46826 And tmpp<=47009) Then
pychar= "E"
ElseIf(tmpp>=47010 And tmpp<=47296) Then
pychar= "F"
ElseIf(tmpp>=47297 And tmpp<=47613) Then
pychar= "G"
ElseIf(tmpp>=47614 And tmpp<=48118) Then
pychar= "H"
ElseIf(tmpp>=48119 And tmpp<=49061) Then
pychar= "J"
ElseIf(tmpp>=49062 And tmpp<=49323) Then
pychar= "K"
ElseIf(tmpp>=49324 And tmpp<=49895) Then
pychar= "L"
ElseIf(tmpp>=49896 And tmpp<=50370) Then
pychar= "M"
ElseIf(tmpp>=50371 And tmpp<=50613) Then
pychar= "N"
ElseIf(tmpp>=50614 And tmpp<=50621) Then
pychar= "O"
ElseIf(tmpp>=50622 And tmpp<=50905) Then
pychar= "P"
ElseIf(tmpp>=50906 And tmpp<=51386) Then
pychar= "Q"
ElseIf(tmpp>=51387 And tmpp<=51445) Then
pychar= "R"
ElseIf(tmpp>=51446 And tmpp<=52217) Then
pychar= "S"
ElseIf(tmpp>=52218 And tmpp<=52697) Then
pychar= "T"
ElseIf(tmpp>=52698 And tmpp<=52979) Then
pychar= "W"
ElseIf(tmpp>=52980 And tmpp<=53640) Then
pychar= "X"
ElseIf(tmpp>=53689 And tmpp<=54480) Then
pychar= "Y"
ElseIf(tmpp>=54481 And tmpp<=62289) Then
pychar= "Z"
Else '如果不是中文,则不处理
pychar= Mid(char,chrInt,1)
End If
getpychar = getpychar & pychar
Next
End function
Dim Str
Str = "早上好"
Response.Write(Str &"<BR>")
Response.Write(getpychar(Str))
%>
[此贴子已经被作者于2007-6-29 8:42:14编辑过]
精简一下,
[CODE]<%
'返回汉字拼音首字母串
Function getpychar(char)
getpychar = ""
Dim charLen,chrInt,tmpp,pychar
charLen = Len(char)
If charLen < 1 Then Exit Function
For chrInt = 1 To charLen
tmpp=65536+asc(Mid(char,chrInt,1))
If(tmpp>=45217 And tmpp<=45252) Then pychar= "A"
If(tmpp>=45253 And tmpp<=45760) Then pychar= "B"
If(tmpp>=45761 And tmpp<=46317) Then pychar= "C"
If(tmpp>=46318 And tmpp<=46825) Then pychar= "D"
If(tmpp>=46826 And tmpp<=47009) Then pychar= "E"
If(tmpp>=47010 And tmpp<=47296) Then pychar= "F"
If(tmpp>=47297 And tmpp<=47613) Then pychar= "G"
If(tmpp>=47614 And tmpp<=48118) Then pychar= "H"
If(tmpp>=48119 And tmpp<=49061) Then pychar= "J"
If(tmpp>=49062 And tmpp<=49323) Then pychar= "K"
If(tmpp>=49324 And tmpp<=49895) Then pychar= "L"
If(tmpp>=49896 And tmpp<=50370) Then pychar= "M"
If(tmpp>=50371 And tmpp<=50613) Then pychar= "N"
If(tmpp>=50614 And tmpp<=50621) Then pychar= "O"
If(tmpp>=50622 And tmpp<=50905) Then pychar= "P"
If(tmpp>=50906 And tmpp<=51386) Then pychar= "Q"
If(tmpp>=51387 And tmpp<=51445) Then pychar= "R"
If(tmpp>=51446 And tmpp<=52217) Then pychar= "S"
If(tmpp>=52218 And tmpp<=52697) Then pychar= "T"
If(tmpp>=52698 And tmpp<=52979) Then pychar= "W"
If(tmpp>=52980 And tmpp<=53640) Then pychar= "X"
If(tmpp>=53689 And tmpp<=54480) Then pychar= "Y"
If(tmpp>=54481 And tmpp<=62289) Then pychar= "Z"
getpychar = getpychar & pychar
Next
End function
Dim Str
Str = "早上好"
Response.Write(Str &"<BR>")
Response.Write(getpychar(Str))
%>[/CODE]