支持中文的URLDecode ASP函数

1、这一部分是不支持中文的UrlDecode转换函数

<%
Function URLDecode(sConvert)
Dim aSplit
Dim sOutput
Dim I
If IsNull(sConvert) Then
URLDecode = ""
Exit Function
End If
' convert all pluses to spaces
sOutput = REPLACE(sConvert, "+", " ")
' next convert %hexdigits to the character
aSplit = Split(sOutput, "%")
If IsArray(aSplit) Then
sOutput = aSplit(0)
For I = 0 to UBound(aSplit) - 1
sOutput = sOutput & _
Chr("&H" & Left(aSplit(i + 1), 2)) &_
Right(aSplit(i + 1), Len(aSplit(i + 1)) - 2)
Next
End If
URLDecode = sOutput
End Function
%>

2、这一部分是支持转换中文的Asp UrlDecode函数

<%
function URLDecode(strIn)
URLDecode = ""
Dim sl: sl = 1
Dim tl: tl = 1
Dim key: key = "%"
Dim kl: kl = Len(key)
sl = InStr(sl, strIn, key, 1)
Do While sl>0
If (tl=1 And sl<>1) Or tl<sl Then
URLDecode = URLDecode & Mid(strIn, tl, sl-tl)
End If
Dim hh, hi, hl
Dim a
Select Case UCase(Mid(strIn, sl+kl, 1))
Case "U":'Unicode URLEncode
a = Mid(strIn, sl+kl+1, 4)
URLDecode = URLDecode & ChrW("&H" & a)
sl = sl + 6
Case "E":'UTF-8 URLEncode
hh = Mid(strIn, sl+kl, 2)
a = Int("&H" & hh)'ascii码
If Abs(a)<128 Then
sl = sl + 3
URLDecode = URLDecode & Chr(a)
Else
hi = Mid(strIn, sl+3+kl, 2)
hl = Mid(strIn, sl+6+kl, 2)
a = ("&H" & hh And &H0F) * 2 ^12 Or ("&H" & hi And &H3F) * 2 ^ 6 Or ("&H" & hl
And &H3F)
If a<0 Then a = a + 65536
URLDecode = URLDecode & ChrW(a)
sl = sl + 9
End If
Case Else:'Asc URLEncode
hh = Mid(strIn, sl+kl, 2)'高位
a = Int("&H" & hh)'ascii码
If Abs(a)<128 Then
sl = sl + 3
Else
hi = Mid(strIn, sl+3+kl, 2)'低位
a = Int("&H" & hh & hi)'非ascii码
sl = sl + 6
End If
URLDecode = URLDecode & Chr(a)
End Select
tl = sl
sl = InStr(sl, strIn, key, 1)
Loop
URLDecode = URLDecode & Mid(strIn, tl)
End function
%>

本博客所有文章如无特别注明均为原创。作者:sysdee复制或转载请以超链接形式注明转自 成功志
原文地址《支持中文的URLDecode ASP函数
分享到:更多

相关推荐

发表评论

路人甲 表情
看不清楚?点图切换 Ctrl+Enter快速提交

网友评论(0)