ruby 代码
- x = "123".to_i # 123
- y = Integer("123") # 123
- x = "junk".to_i # 0
- y = Integer("junk") # error
- # 遇到非数字字符时,to_i方法将停止转换, 将Integer将引发错误
- x = "123junk".to_i # 123
- y = Integer("123junk") # error
- # 允许字符串的开头和末尾有空白
- x = " 123 " # 123
- y = Integer(" 123 ") # 123