URLDecode - The one - ASP/VBScript

This is a discussion on "URLDecode - The one - ASP/VBScript" within the Classic ASP section. This forum, and the thread "URLDecode - The one - ASP/VBScript are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 9th, 2006, 13:41
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,620
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Wink URLDecode - The one - ASP/VBScript

The name of the function should say it all. It decodes anything encoded using Server.URLEncode(...).

I needed a complete function to use complement my new Ajax scripts (Ajax requests are 'URL encoded' by the client). I found several scripts but each had a flaw/something missing.

I believe this is the one. Enjoy!
PS.: If you like it, gimme some brownies! (reputation)

Code: Select all
Function UrlDecode(ByVal output)
 On Error Resume Next
    
    output = "" & output
    If output<>"" Then
     Dim i, h, ce, cd
        
        ' convert all pluses to spaces
        output = Replace(output, "+", " ")
        
        ' single quotes, not latin accent character
        output = Replace(output, "%22", Chr(34))
     
        ' convert %hexdigits to the character
        i = InStr(1, output, "%")
        Do While i>0
            h = "&H" & Mid(output, i+1, 2) & ""
            ce = "" & Mid(output, i, 3) & ""
            cd = "" & Chr(CLng(h)) & ""
            If cd <> "" Then
                ' HIDE % (%25 = %)
                If cd = "%" Then cd = "-!-"
                ' % is special - replacing it now would cause
                ' an endless loop. so let's just mark its location
                ' and replace it at the end of the routine
            
            Else
                ' if we can't produce a character, put string back
                ' and hide % sign until the end of the routine
                cd = Replace(ce, "%", "-!-")
            
            End If
            
            ' replace character
            output = Replace(output, ce, cd)
            
            ' find next hex character
            i = InStr(1, output, "%")
        Loop
        
  ' put % signs back
        output = Replace(output, "-!-", "%")
  
    End If
    URLDecode = output
End Function
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)

Last edited by spinal007; Aug 9th, 2006 at 14:06.
Reply With Quote

Reply

Tags
urldecode, aspvbscript

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Keep getting error message Microsoft VBScript runtime error '800a01a8' cpando1974 Classic ASP 2 Aug 7th, 2007 12:00
VBScript Hell moojoo Other Programming Languages 1 Oct 10th, 2006 20:44
Help on ASP procedure with VBScript malambing57 Classic ASP 6 Apr 26th, 2004 17:05
VBScript.... courtjester Classic ASP 3 Feb 3rd, 2004 09:13
calling a javascript function in from VBscript jakyra Classic ASP 2 Sep 22nd, 2003 23:13


All times are GMT. The time now is 00:09.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43