Converting %2F back to /

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?

···

--
Posted via http://www.ruby-forum.com/.

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
dougal.s@gmail.com
http://douglasfshearer.com

···

On 19 Aug 2007, at 21:15, Dipesh Batheja wrote:

Great Post.I like the link.Now expecting some good ideas from your

upcoming post

···

--
Posted via http://www.ruby-forum.com/.

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

Found in the standard library. :slight_smile:

Cheers

  robert

···

On 19.08.2007 22:30, Douglas F Shearer wrote:

On 19 Aug 2007, at 21:15, Dipesh Batheja wrote:

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.

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

···

On Mon, Nov 29, 2010 at 10:29 AM, Steve Austen <steveausten555@gmail.com>wrote:

Great Post.I like the link.Now expecting some good ideas from your

upcoming post
http://www.dealsourcedirect.com/ion-tape2pc.html

--
Posted via http://www.ruby-forum.com/.

It had to be there somewhere, thanks for pointing it out! :o)

Douglas F Shearer
dougal.s@gmail.com
http://douglasfshearer.com

···

On 19 Aug 2007, at 22:09, Robert Klemme wrote:

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

Found in the standard library. :slight_smile: