From: Justus Ohlhaver Date: 2008-11-12T23:39:30+09:00 Subject: Re: Convert text string i.e 'Peter' into integer ID Hugh Sasse wrote: > On Wed, 12 Nov 2008, Justus Ohlhaver wrote: > >> Hello, >> >> is there any method to quickly convert a text string such as 'Peter' >> into an integer? (And vice versa?) >> >> I am not asking about just changing the format (to_i). I'm looking for a >> method thus can do the computation. > > What properties do you want the string:integer relationship to have? > The problem is too unbounded at the moment. > > ["Peter", "James", "John", "Andrew"].index("Peter") > > satisfies the constraints given so far. >> >> Thanks, >> Justus > > Hugh Thanks for your help. No I need to turn the string which would usually be a headline ('Man lands on the moon') into a unique number. The purpose is to speed up my database queries when checking whether an entry with the same headline already exists in the db. Justus -- Posted via http://www.ruby-forum.com/.