URL編碼是指為了將信息通過URL進行傳輸,所以必須將某些含有特殊意義的字符進行替換的一種編碼方式,在asp中我們都知道有一個Server.URLEncode的函數可以完成這個功能。即:
  如果有空格就用%20代替,如果有其它字符就用%ASCII代替,如果有漢字等四個字節的字符,就用兩個%ASCII來代替。不過有時候我們也需要將經過這種編碼的字符串進行解碼,但asp並沒有提供相關的函數,這給我們處理問題帶來了一定的麻煩。其實我們隻要知道了編碼規則後,就可以用asp代碼來實現我們自己的URlDecode函數了。
function urldecode(encodestr) 
Dim newstr,havechar,lastchar,i,char_c,next_1_c,next_1_Num
newstr="" 
havechar=false 
lastchar="" 
for i=1 to len(encodestr) 
   char_c=mid(encodestr,i,1) 
   if char_c="+" then 
    newstr=newstr & " " 
   elseif char_c="%" then 
    next_1_c=mid(encodestr,i+1,2) 
    next_1_num=cint("&H" & next_1_c) 
   
    if havechar then 
     havechar=false 
     newstr=newstr & chr(cint("&H" & lastchar & next_1_c)) 
    else 
     if abs(next_1_num)<=127 then 
      newstr=newstr & chr(next_1_num) 
     else 
      havechar=true 
      lastchar=next_1_c 
     end if 
    end if 
    i=i+2 
   else 
    newstr=newstr & char_c 
   end if 
next 
urldecode=newstr 
end function




