Mike Stok wrote:
>
> On 26-Aug-07, at 4:32 PM, James Edward Gray II wrote:
>
>> On Aug 26, 2007, at 3:26 PM, Kenneth McDonald wrote:
>>
>>> The real problem is:
>>>
>>> irb(main):002:0> "12,345".to_i
>>> => 12
>>>
>>> Basically, Ruby converts anything that starts with an int, which is 
>>> really quite nasty in a case such as the above. I spent a lot of 
>>> time tracking down that problem.
>>>
>>> So, I want an integer conversion function that throws an error if 
>>> the _entire_ string can't be interpreted as an integer; the Ruby 
>>> analog to the standard string-to-int conversion function in most 
>>> other languages.
>>
>> raise "Bad integer" unless i_str =~ /\A-?\d+\z/
>
> What about
>
>   int = Integer(i_str)
>
> ?
>
> It accepts leading whitespace, but apart from that it's pretty picky.
>
> Mike
This is what I was looking for. There's nothing wrong with the regexp 
solution of course, it's just that Simpler is Nicer :-).  Many thanks to 
both of you.

Cheers,
Ken
>
> -- 
> Mike Stok <mike / stok.ca>
> http://www.stok.ca/~mike/
>
> The "`Stok' disclaimers" apply.
>
>
>
>
>
>