SHARE
TWEET

URL_Encode_Decode.vbs

hackoo Feb 11th, 2020 (edited) 506 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Question : Decoding URL encoded UTF-8 strings in VBScript
  2. 'URL : https://stackoverflow.com/questions/17880395/decoding-url-encoded-utf-8-strings-in-vbscript?answertab=active#tab-top
  3. Option Explicit
  4. Dim JSEngine,ws,WSC
  5. Set ws = CreateObject("WScript.Shell")
  6. WSC = ws.ExpandEnvironmentStrings("%AppData%\urlencdec.wsc")
  7. Call Create_URL_ENC_DEC_Component(WSC)
  8. Set JSEngine = GetObject("Script:"& WSC)
  9.  
  10. WScript.Echo JSEngine.decode("%D9%81%D9%8A%D9%84%D9%85-21Bridges-2019-%D9%85%D8%AA%D8%B1%D8%AC%D9%85")
  11. WScript.Echo JSEngine.decode("%D9%81%D9%8A%D9%84%D9%85-Dolittle-2020-%D9%85%D8%AA%D8%B1%D8%AC%D9%85")
  12. WScript.Echo JSEngine.encode("Paris → Zürich")
  13.  
  14. '--------------------------------------------------------------------------------------------------------
  15. Sub Create_URL_ENC_DEC_Component(WSC)
  16. Dim fso,File
  17. Set fso = CreateObject("Scripting.FileSystemObject")
  18. Set File = fso.OpenTextFile(WSC,2,True)
  19. File.WriteLine "<?xml version=""1.0""?>"
  20. File.WriteLine "<component>"
  21. File.WriteLine "<?component error=""true"" debug=""true""?>"
  22. File.WriteLine     "<registration"
  23. File.WriteLine         "description=""Url Encode / Decode Helper"""
  24. File.WriteLine         "progid=""JSEngine.Url"""
  25. File.WriteLine         "version=""1.0"""
  26. File.WriteLine         "classid=""{80246bcc-45d4-4e92-95dc-4fd9a93d8529}"""
  27. File.WriteLine     "/>"
  28. File.WriteLine    "<public>"
  29. File.WriteLine         "<method name=""encode"">"
  30. File.WriteLine             "<PARAMETER name=""s""/>"
  31. File.WriteLine         "</method>"
  32. File.WriteLine         "<method name=""decode"">"
  33. File.WriteLine             "<PARAMETER name=""s""/>"
  34. File.WriteLine         "</method>"
  35. File.WriteLine     "</public>"
  36. File.WriteLine     "<script language=""JScript"">"
  37. File.WriteLine     "<![CDATA["
  38. File.WriteLine         "var description = new UrlEncodeDecodeHelper;"
  39. File.WriteLine         "function UrlEncodeDecodeHelper() {"
  40. File.WriteLine             "this.encode = encode;"
  41. File.WriteLine             "this.decode = decode;"
  42. File.WriteLine         "}"
  43. File.WriteLine         "function encode(s) {"
  44. File.WriteLine            "return encodeURIComponent(s).replace(/'/g,""%27"").replace(/""/g,""%22"");"
  45. File.WriteLine         "}"
  46. File.WriteLine         "function decode(s) {"
  47. File.WriteLine             "return decodeURIComponent(s.replace(/\+/g,  "" ""));"
  48. File.WriteLine         "}"
  49. File.WriteLine     "]]>"
  50. File.WriteLine     "</script>"
  51. File.WriteLine "</component>"
  52. End Sub
  53. '--------------------------------------------------------------------------------------------------------
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top