README.md

December 5, 2022 ยท View on GitHub

URLEncode opposite (URLDecode)

Description

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.

More Info

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.

Submitted On
By----------
LevelAdvanced
User Rating5.0 (10 globes from 2 users)
CompatibilityASP (Active Server Pages), VbScript (browser/client side)

Category |Algorithims World |ASP / VbScript Archive File |

Source 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