- trim
Convert string to number that ends with newline
examples/convert/string-to-int-fail/src/main.rs
fn main() { let text = "23\n"; println!("'{}'", text); let number: i32 = text.parse().expect("Could not convert to i32"); println!("'{}'", number); println!("'{}'", number + 1); }
'23 ' thread 'main' panicked at 'Could not convert to i32: ParseIntError { kind: InvalidDigit }', string_to_int_fail.rs:6:10 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace