📜  ruby 字符串到 int - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:45.293000             🧑  作者: Mango

代码示例1
a = "42" # => '42'
a.to_i # => 42

# But if you might not have a number in your String, you should rather 
# use this instead, as to_i doesn't throw an Error:

"42test123".to_i # => 42
Integer("42test123") # => ArgumentError
Integer("42") # => 42