Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Converting %2F back to /

Reply
Thread Tools

Converting %2F back to /

 
 
Dipesh Batheja
Guest
Posts: n/a
 
      08-19-2007
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/.

 
Reply With Quote
 
 
 
 
Douglas F Shearer
Guest
Posts: n/a
 
      08-19-2007
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://www.velocityreviews.com/forums/(E-Mail Removed)
http://douglasfshearer.com

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      08-19-2007
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
 
Reply With Quote
 
Douglas F Shearer
Guest
Posts: n/a
 
      08-19-2007
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! )

Douglas F Shearer
(E-Mail Removed)
http://douglasfshearer.com

 
Reply With Quote
 
Steve Austen
Guest
Posts: n/a
 
      11-29-2010
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/.

 
Reply With Quote
 
Jamey Cribbs
Guest
Posts: n/a
 
      11-29-2010
[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 <(E-Mail Removed)>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/.
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Float to unsigned short and Back avsrk@mailcity.com C Programming 8 05-17-2006 04:27 PM
Converting floats to Strings and back dcMan Java 7 11-23-2005 10:58 AM
Converting NTFS back to FAT32 On an External Drive buck Computer Information 11 11-21-2005 11:38 PM
debugging - converting PyObject back to a variable name adamc Python 0 06-22-2005 06:45 PM
Converting from and INT back to ASCII character David Williams C++ 12 10-10-2003 09:34 AM



Advertisments