String conversion, from a base to an other new one

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(8), str.to_s(16), str.to_s(32)… but I don’t see how to
change chars.

Thank you for any suggestions.

On 7/6/09, Zangief I. [email protected] 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: “ù=*$`^~£” chars)?
I have used abcdefgh for readability but I guess you got the idea :wink:

irb(main):006:0> “3m74jnfu9f”.to_i(32).to_s(8).tr(“01234567”,“abcdefgh”)
=> “dfedeeehdfhheefh”

HTH
Robert


Toutes les grandes personnes ont d’abord été des enfants, mais peu
d’entre elles s’en souviennent.

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

[Antoine de Saint-Exupéry]

Work perfecly. Thanks!