From: Mike Moore Date: 2007-07-14T06:09:53+09:00 Subject: Re: Base 26 ------=_Part_24516_2608582.1184360992470 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/13/07, Peter Cooper wrote: > > On 7/13/07, Phrogz wrote: > > > > On Jul 13, 2:39 pm, Stefan Rusterholz wrote: > > > Mike Moore wrote: > > >> Hey friends! What is the best way to convert a Numeric to a string > > >> encoded > > >> with base 26? I want the string to contain just alpha characters, > not > > >> alphanumeric characters. For now I'm using num.to_s(26).tr('0-9a-p', > > >> 'a-z') > > >> and I'm wondering if there is a more concise way. > > > Anyway, if you need that instead of what to_s(26) already does, then I > > > don't know a shorter way. > > > > How about (i+10).to_s(36) > > > If it ends up in base 36 then it's still going to get numbers in it, just > not for the first ten numbers! :) > > To the original poster.. no, it looks like you're doing it the best way > IMHO. What you are trying to do is not standard (that is, base 26 is > 0-9a-p), so a single 'tr' is nothng to sniff at to get your special > variant > :) Just abstract it away into your own method on Fixnum/Numeric if you > want > to keep it lean in your other code. Thanks Peter. I didn't mean to sniff at a single 'tr', I was just hoping for a better way. Right now I have my 'to_base26' and 'from_base26' methods on Numeric and String respectively, but I think I might monkey-patch 'to_s' and 'to_i' and add the base 26 logic when the 'base' argument is 26. Cheers, > Peter Cooper > http://www.rubyinside.com/ > ------=_Part_24516_2608582.1184360992470--