URL decoding with Ruby
Published Date: September 9, 2022
Updated Date: September 9, 2022
In order to encode a string or a URL in Ruby, you can use the CGI::Escape method. This method will escape or encode the string or URL in Ruby.
How to encode a string or a URL in RUBY
require 'cgi'
url_encoded_string = CGI.escape("Enc@de my Str!ng in @Ruby")
puts url_encoded_string
Output:
# Output
Enc%40de%20my%20Str%21ng%20in%20%40Ruby
Similarly, if we want to decode a string or URL in Ruby, we can make sue of the CGI::Unescape method. This method will unescape or decode the string or URL in Ruby.
How to decode a string or a URL in RUBY
require 'cgi'
url_decoded_string = CGI.unescape("Dec%40de%20my%20Str%21ng%20in%20%40Ruby")
puts url_encoded_string
Output:
# Output
Dec@de my Str!ng in @Ruby
Related Decoding techniques:
- URL decoding with Javascript
- URL decoding with Python
- URL decoding with Ruby
- URL decoding with Java
- URL decoding with Golang
Related Encoding techniques:
- URL encoding with Javascript
- URL encoding with Python
- URL encoding with Ruby
- URL encoding with Java
- URL encoding with Golang
There are many applications that require you to encode your URL into a format that the systems can understand. If you wish to encode a URL, check out our free online URL Encoder.
Some systems communicate with encoded URLs, so you may need to decode a URL. If you want to decode a URL online, we have our free online URL Decoder.