ASP coding and decoding functions _ Application Skills

Source: Internet
Author: User

A decoding problem is encountered when developing with ASP. Although using Request in ASP to get encoded URL strings will automatically decode, but Request.BinaryRead (request.totalbytes) when the post data is not decoded, so can only manually decode.
ASP decoding function:

Function UrlDecode (enstr) 
 Dim destr,strspecial 
 Dim C,i,v 
  destr= "
  strspecial="! "" #$%& ' () *+,.-_/:;<=>?@[/]^ ' {|} ~% "for
  I=1 to Len (enstr) 
   c=mid (enstr,i,1) 
   if c="% "then 
    v=eval (" &h "+mid (enstr,i+1,2)) 
    if InStr (STRSPECIAL,CHR (v)) >0 then 
     destr=destr&chr (v) 
     i=i+2 
    Else
     v=eval ("&h" + Mid ( enstr,i+1,2) + Mid (enstr,i+4,2)) 
     Destr=destr & Chr (v) 
     i=i+5 End 
    If
   else
    if c= "+" then 
     destr=destr& ""
    else
     destr=destr&c end 
    If
  next 
  urldecode=destr End 
function

Just a personal hobby, I studied the coding of the implementation of ideas, and finally wrote a code function, to provide you with reference. Note: ASP has the built-in coding function, that is server.urlencode.

ASP encoding function:

Private Function urlencoding (vstrin) 
  strreturn = "for
  i = 1 to Len (vstrin) 
  THISCHR = Mid (vstrin,i,1) 
  If Abs (ASC (THISCHR)) < &hff Then 
  strreturn = strreturn & thischr 
  Else 
  innercode = ASC (THISCHR) 
  If Innercode < 0 Then 
  Innercode = innercode + &h10000 end 
  If 
  Hight8 = (Innercode and &hff00)/&am P HFF 
  Low8 = Innercode and &hff 
  strreturn = strreturn & "%" & Hex (HIGHT8) & "%" & Hex (LOW8) 
   end If 
  Next 
  urlencoding = Strreturn End 
Function

It is recommended that you use the ASP built-in functions when coding in Chinese. Although the above coded function has been tested n times, no problems have been identified, but in case there is a bug.

The above is about ASP encoding and decoding functions, I hope to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.