Converting %2F back to /

D

Dipesh Batheja

I have a string which contains url. The forward slash in it represented
in '%2F' and I want to convert this back to '/'. How can i do that?
 
D

Douglas F Shearer

I have a string which contains url. The forward slash in it
represented
in '%2F' and I want to convert this back to '/'. How can i do that?

I had to the same thing a while back:

def url_decode(s)
s.gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
[$1.delete('%')].pack('H*')
end
end
s = "Hello there everyone!" => "Hello there everyone!"
u(s)
=> "Hello%20there%20everyone%21"
url_decode(u(s))
=> "Hello there everyone!"

Found this via google originally.

Douglas F Shearer
(e-mail address removed)
http://douglasfshearer.com
 
R

Robert Klemme

I have a string which contains url. The forward slash in it represented
in '%2F' and I want to convert this back to '/'. How can i do that?

I had to the same thing a while back:

def url_decode(s)
s.gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
[$1.delete('%')].pack('H*')
end
end
s = "Hello there everyone!" => "Hello there everyone!"
u(s)
=> "Hello%20there%20everyone%21"
url_decode(u(s))
=> "Hello there everyone!"

Found this via google originally.

irb(main):001:0> require 'uri'
=> true
irb(main):002:0> URI.decode "a%2Fb"
=> "a/b"

Found in the standard library. :)

Cheers

robert
 
J

Jamey Cribbs

[Note: parts of this message were removed to make it a legal post.]

Steve, I really enjoyed the Six Million Dollar Man, but, now, I kind of wish
you would shove your bionic arm up your own ass and quit spamming this list.

Sincerely,

Jamey (Not Sommers) Cribbs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top