From: Todd Benson Date: 2008-11-12T23:55:57+09:00 Subject: Re: Convert text string i.e 'Peter' into integer ID On Wed, Nov 12, 2008 at 8:47 AM, Jan Friedrich wrote: > Justus Ohlhaver wrote: > >> Hugh Sasse wrote: >> 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 > I would do something like this with a md5 hash: > > require 'digest/md5' > Digest::MD5.hexdigest('Peter') > # => "6fa95b1427af77b3d769ae9cb853382f" > > Regards > Jan Unless I'm missing something here, strings are just numbers in order. Why encode/encrypt? Most db's should handle natural keys. If absolutely necessary to store as number strings (I can't see why), look at #pack and #unpack. Todd