A similar urlencode coding function and corresponding decoding function implemented in ASP

Source: Internet
Author: User
Tags count urlencode
encode| Code | function

<%
' Coding.inc.asp
' All Rights Reserved, Room3rd@hotmail.com

Function Encode (Str)
 dim Count, Pos, Ch, Code
 dim sweetch
 
  Characters in Sweetch that do not need to be encoded
 sweetch = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz_{}[]" ()
 encode = "
 
 count = Len (Str)
 pos = 1
 do while Pos<=count
 & nbsp Ch = Mid (Str, Pos, 1)
  
  code = ASC (ch)
  if code>=0 and code<256 then& nbsp;  ' Kanji not processed
   if ch<> "%" Then
    if InStr (Sweetch, Ch) =0 Then
     ch = "%" & Right ("0" & Hex (Code), 2)
    end If
   else
    ch = "%25"
   end if
  end if
  
  encode = Encode & Ch
  pos = Pos + 1
 loop
End Function

Function Decode (STR)
Dim Count, Pos, Ch, Code

Decode = ""

Count = Len (STR)
Pos = 1
Do While Pos<=count
Ch = Mid (Str, Pos, 1)
If ch= "%" Then
If Pos+2<=count Then
Ch = Chr (InStr ("0123456789ABCDEF", UCase (Mid (str, pos+1, 1))-1) * + InStr ("0123456789ABCDEF", UCase (Mid (str, pos+2, 1 ))-1)
Else
' Coded string is incorrect
Ch = ""
End If
pos = pos + 2
End If
Decode = Decode & Ch
pos = pos + 1
Loop
End Function
%>



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.