From: Peter Szinek Date: 2008-11-12T23:35:08+09:00 Subject: Re: Convert text string i.e 'Peter' into integer ID On 2008.11.12., at 14:16, Justus Ohlhaver wrote: > Hello, > > is there any method to quickly convert a text string such as 'Peter' > into an integer? (And vice versa?) There are a lot of easy ways to do the string -> integer part - e.g. 1) def x(s); return 42; end # now you can call x on your string and it will convert it to an integer 2) "Peter"[0] 3) "Peter".object_id 4) "Peter".hash The integer -> string part is the real problem; it's impossible to do it with methods 1) - 3), with some extra effort (storing the result in a lookup table) it should be possible to accomplish it with 4) unless you have some extra requirements. The question is, what do you really want to achieve? What properties should the mapping have? Cheers Peter