Logo

Programming-Idioms

History of Idiom 22 > diff from v32 to v33

Edit summary for version 33 by :
[Ruby] +DocURL

Version 32

2015-12-30, 21:31:10

Version 33

2015-12-30, 21:34:50

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Code
i = s.to_i
Code
i = s.to_i
Comments bubble
"123".to_i returns 123
"abc".to_i returns 0
Comments bubble
to_i returns 0 if s is not a valid number.
Doc URL
http://ruby-doc.org/core-2.3.0/String.html#to_i-method