(VBScript) URL Encoding and Decoding
Demonstrates URL encoding and decoding.
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
' To URL encoding a string:
s = "Why a > b?"
' For versions of Chilkat < 10.0.0, use CreateObject("Chilkat_9_5_0.StringBuilder")
set sb = CreateObject("Chilkat.StringBuilder")
success = sb.Append(s)
' URL encode the string.
success = sb.Encode("url","utf-8")
' Show the URL encoded string:
sEncoded = sb.GetAsString()
outFile.WriteLine(sEncoded)
' The result is: Why%20a%20%3E%20b%3F
' If you prefer "+" instead of "%20" for SPACE chars:
numReplaced = sb.Replace("%20","+")
outFile.WriteLine(sb.GetAsString())
' Output is: Why+a+%3E+b%3F
' To decode:
success = sb.Decode("url","utf-8")
outFile.WriteLine(sb.GetAsString())
' Result is: Why a > b?
outFile.Close
|