Lua
Lua
URL Encoding and Decoding
See more Encryption Examples
Demonstrates URL encoding and decoding.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- To URL encoding a string:
local s = "Why a > b?"
local sb = chilkat.StringBuilder.new()
local success = sb:append(s)
-- URL encode the string.
sb:encode("url", "utf-8")
-- Show the URL encoded string:
local sEncoded = sb:get_as_string()
print(sEncoded)
-- The result is: Why%20a%20%3E%20b%3F
-- If you prefer "+" instead of "%20" for SPACE chars:
local numReplaced = sb:replace("%20", "+")
print(sb:get_as_string())
-- Output is: Why+a+%3E+b%3F
-- To decode:
sb:decode("url", "utf-8")
print(sb:get_as_string())
-- Result is: Why a > b?