A
Artur Merke
Hi,
taken from the ruby book:
str.to_i -> anInteger
Returns the result of interpreting leading characters in str as a decimal
integer. Extraneous characters past the end of a valid number are ignored.
If there is not a valid number at the start of str, 0 is returned. The
method never raises an exception.
example
"hello".to_i
»
0
Is there a way to recognize if the conversion was successful? If
"0".to_i and "any string".to_i deliver the same result, I don't see how
this could be accomplished, without separately checking the syntax of the
given string.
Why doesn't "hello".to_i deliver a nil as a return value, which can
clearly be recognized as a conversion failure?
Artur
_______________________________________________________________________________
Artur Merke
||| (e-mail address removed)
(O-O)
_____________________________________________.oo0--(_)--0oo.___________________
taken from the ruby book:
str.to_i -> anInteger
Returns the result of interpreting leading characters in str as a decimal
integer. Extraneous characters past the end of a valid number are ignored.
If there is not a valid number at the start of str, 0 is returned. The
method never raises an exception.
example
"hello".to_i
»
0
Is there a way to recognize if the conversion was successful? If
"0".to_i and "any string".to_i deliver the same result, I don't see how
this could be accomplished, without separately checking the syntax of the
given string.
Why doesn't "hello".to_i deliver a nil as a return value, which can
clearly be recognized as a conversion failure?
Artur
_______________________________________________________________________________
Artur Merke
||| (e-mail address removed)
(O-O)
_____________________________________________.oo0--(_)--0oo.___________________