Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > String conversion, from a base to an other new one

Reply
Thread Tools

String conversion, from a base to an other new one

 
 
Zangief Ief
Guest
Posts: n/a
 
      07-06-2009
Hello,

Is there a way, in Ruby, to convert this kind of value: "3m74jnfu9f"
(which is in base 32 having: "0123456789abcdefghijklmnopqrstuv" chars)
into a other new base, for instance a base 8 (having: "ù=*$`^~£" chars)?

to_s method seems intersting, its allow to pass into many bases such
with str.to_s(, str.to_s(16), str.to_s(32)... but I don't see how to
change chars.

Thank you for any suggestions.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Dober
Guest
Posts: n/a
 
      07-06-2009
On 7/6/09, Zangief Ief <(E-Mail Removed)> wrote:
> Hello,
>
> Is there a way, in Ruby, to convert this kind of value: "3m74jnfu9f"
> (which is in base 32 having: "0123456789abcdefghijklmnopqrstuv" chars)
> into a other new base, for instance a base 8 (having: "=F9=3D*$`^~=A3" ch=

ars)?
I have used abcdefgh for readability but I guess you got the idea

irb(main):006:0> "3m74jnfu9f".to_i(32).to_s(.tr("01234567","abcde fgh")
=3D> "dfedeeehdfhheefh"

HTH
Robert


--=20
Toutes les grandes personnes ont d=92abord =E9t=E9 des enfants, mais peu
d=92entre elles s=92en souviennent.

All adults have been children first, but not many remember.

[Antoine de Saint-Exup=E9ry]

 
Reply With Quote
 
 
 
 
Zangief Ief
Guest
Posts: n/a
 
      07-06-2009
Work perfecly. Thanks!
--
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
Looking for ASP.NET Facebook Style one to one Chat for my social media site Ajax base JaySMina Software 0 01-19-2012 01:50 PM
Virtual inheritace -- when one inheritance of the base is virtual andthe other isn't. pauldepstein@att.net C++ 1 03-14-2009 03:45 PM
New Zealand, on the other hand, has one of the lowest growth rates and one of the lowest levels of broadband penetration in the world. punlic NZ Computing 6 05-02-2004 10:28 AM
Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream' tomek C++ 2 12-01-2003 06:31 AM
Virtual function 'BasicMidReader::~BasicMidReader()' conflicts with base class 'base 'TMemoryStream' tomek C++ 3 11-30-2003 12:18 AM



Advertisments