Converting %2F back to /

Discussion in 'Ruby' started by Dipesh Batheja, Aug 19, 2007.

  1. 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/.
    Dipesh Batheja, Aug 19, 2007
    #1
    1. Advertising

  2. 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.

    Douglas F Shearer

    http://douglasfshearer.com
    Douglas F Shearer, Aug 19, 2007
    #2
    1. Advertising

  3. 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.


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

    Found in the standard library. :)

    Cheers

    robert
    Robert Klemme, Aug 19, 2007
    #3
  4. 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. :)


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

    Douglas F Shearer

    http://douglasfshearer.com
    Douglas F Shearer, Aug 19, 2007
    #4
  5. Dipesh Batheja

    Steve Austen Guest

    Steve Austen, Nov 29, 2010
    #5
  6. Dipesh Batheja

    Jamey Cribbs Guest

    Re: Convert Cassette to CD

    [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



    On Mon, Nov 29, 2010 at 10:29 AM, Steve Austen <>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/.
    >
    >
    >
    Jamey Cribbs, Nov 29, 2010
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dcMan
    Replies:
    7
    Views:
    1,663
    Chris Uppal
    Nov 23, 2005
  2. David Williams
    Replies:
    12
    Views:
    600
    Karl Heinz Buchegger
    Oct 10, 2003
  3. adamc
    Replies:
    0
    Views:
    391
    adamc
    Jun 22, 2005
  4. Replies:
    8
    Views:
    452
    Vladimir Oka
    May 17, 2006
  5. WC Justice

    Converting from Access back end to SQL Server

    WC Justice, Jul 13, 2003, in forum: ASP General
    Replies:
    0
    Views:
    108
    WC Justice
    Jul 13, 2003
Loading...

Share This Page