ASP中只有UrlEncode,沒有Urldecode問題的解決方法?
在ASP中傳遞參數(shù)時(shí)有一個很有用的系統(tǒng)函數(shù)Server.UrlEncode,可以將一些非字母數(shù)字的特殊符號轉(zhuǎn)換成標(biāo)準(zhǔn)URL編碼(其實(shí)就是16進(jìn)制ASC碼),這樣就解決了參數(shù)傳遞問題,然后我以為也提供了Server.UrlDecode,但使用后卻發(fā)現(xiàn)程序報(bào)錯,原來系統(tǒng)并沒有提供這個我想象中的解碼函數(shù)。怎幺辦,自己動手吧。
UrlEncode的原理其實(shí)很簡單,就是將特殊字符轉(zhuǎn)換成16進(jìn)制ASC碼值,那么譯碼函數(shù)就只要將16進(jìn)制ASC轉(zhuǎn)回對應(yīng)的字符就OK了。
Function URLDecode(enStr) 'URL解碼函數(shù)
dim deStr
dim c,i,v
deStr=""
for i=1 to len(enStr)
c=Mid(enStr,i,1)
if c="%" then
v=eval("&h"+Mid(enStr,i+1,2))
if v<128 then
deStr=deStr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+Mid(enStr,i+1,2)+Mid(enStr,i+4,2))
deStr=deStr&chr(v)
i=i+5
else
v=eval("&h"+Mid(enStr,i+1,2)+cstr(hex(asc(Mid(enStr,i+3,1)))))
deStr=deStr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
deStr=deStr&" "
else
deStr=deStr&c
end if
end if
next
URLDecode=deStr
end function
function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="A") and (c<="Z"))) then isvalidhex=false:exit function
end function
經(jīng)測試gb312格式的asp使用沒有問題。
相關(guān)文章
asp下根據(jù)標(biāo)題生成關(guān)鍵字的代碼
實(shí)現(xiàn)的功能是:標(biāo)題+標(biāo)題里除去非中文及中文標(biāo)點(diǎn)外的字符的、相鄰兩個字符的集合 傳說中這是采集文章處理keywords的最佳方式,呵呵,做了一個,用下試試2008-06-06
十萬條Access數(shù)據(jù)表分頁的兩個解決方法
后臺數(shù)據(jù)庫用是Access,客戶用了一年后說打開界面非常慢,查看了數(shù)據(jù)庫后發(fā)現(xiàn)數(shù)據(jù)表中的記錄已有五萬多條,自己試過將記錄復(fù)制到10 萬條,打開界面非常慢,翻頁也是同樣的問題2008-06-06
ASP去掉字符串頭尾連續(xù)回車和空格的Function
去掉字符串頭尾的連續(xù)的回車和空格 去掉字符串開頭的連續(xù)的回車和空格 去掉字符串末尾的連續(xù)的回車和空格2008-12-12
在VBScript中實(shí)現(xiàn)-函數(shù)/方法名作為參數(shù)傳入另一個函數(shù)
在VBScript中實(shí)現(xiàn)-函數(shù)/方法名作為參數(shù)傳入另一個函數(shù)...2007-08-08

