From: "Søren Andersen" Date: 2007-10-28T06:43:33+09:00 Subject: Re: Change a string to an integer, report an error if the st ------=_Part_8680_10312694.1193521415012 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I usually use a quick and dirty hack to avoid regexps (though they're nice. :-) def is_integer(to_test) begin Integer(to_test) return true rescue ArgumentError return false end end Basically, I think whoever wrote the Integer-class is smarter than me, so why not let them figure it out? It's probably an abuse of exceptions, but it works just fine. Regards, S=F8ren Andersen On 10/25/07, Lloyd Linklater wrote: > > One caveat is that integers can have alpha characters in the string, > e.g. hex. > > > p '2a'.to_i(16) # =3D> 42 > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_8680_10312694.1193521415012--