URLEncode opposite (URLDecode)
Posted: 2002-06-01
By: ArchiveBot
Viewed: 90
Filed Under:
No attachments for this post
The function Server.URLEncode converts a inputstring to an URL encoded outputstring. For example:
input: Server.URLEncode("part1?part2")
output: "part1%3Fpart2"
But what if you need the opposite functionality ? There is no function available for this so you have build this yourself. How ? By using regular expressions, of course.
Original Author: ----------
Assumptions
This function searches for %[HEX VALUE][HEX VALUE] and replaces them by converting [HEX VALUE][HEX VALUE] to an integer an converting the integer to an ASCII character.
Code
Function URLDecode(sText)
sDecoded = sText
Set oRegExpr = Server.CreateObject("VBScript.RegExp")
oRegExpr.Pattern = "%[0-9,A-F]{2}"
oRegExpr.Global = True
Set oMatchCollection = oRegExpr.Execute(sText)
For Each oMatch In oMatchCollection
sDecoded = Replace(sDecoded,oMatch.value,Chr(CInt("&H" & Right(oMatch.Value,2))))
Next
URLDecode = sDecoded
End Function
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.