0

I have a string with URL data, ex: "http://www.amazon.com" and I would like to receive "http%3A%2F%2Famazon.com".

After reading different posts I am using this command:

irb(main):025:0> require 'open-uri'
=> true
irb(main):026:0> URI.encode("http://www.amazon.com")
=> "http://www.amazon.com"
irb(main):027:0> 

As you can see I receive my string instead of "http%3A%2F%2Famazon.com".

I really appreciate your help and time.

1 Answer 1

4

Use

CGI.escape("http://www.amazon.com")
 #=> "http%3A%2F%2Fwww.amazon.com" 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.