- trim_end
- to_string
Rust - read STDIN - remove trailing newline (trim, chomp)
- trim_end removes trailing whitespace.
- to_string Converts the String to be able to assign to name again
examples/stdin/hello-name-chomp/src/main.rs
use std::io; fn main() { let mut name = String::new(); println!("Please type in your name:"); io::stdin() .read_line(&mut name) .expect("Failed to get input"); name = name.trim_end().to_string(); println!("Hello {}, how are you?", name); }