Implementation of URL coding _asp based on ASP

Source: Internet
Author: User
URL encoding means that in order to transfer information through the URL, some characters that have special meanings must be replaced by a coding method, in the ASP we all know that there is a server.urlencode function to complete this function. That
If there are spaces to replace with%20, if there are other characters to replace with%ASCII, if there are characters such as four bytes of character, the use of two%ascii to replace. But sometimes we also need to decode this encoded string, but the ASP does not provide related functions, which gives us some trouble dealing with the problem. In fact, as long as we know the coding rules, we can use the ASP code to implement our own UrlDecode function.

Specifically implemented as follows:

Copy Code code as follows:
function UrlDecode (ENCODESTR)
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

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.