Skip to content

Instantly share code, notes, and snippets.

@maretekent
Created February 10, 2018 18:21
Show Gist options
  • Save maretekent/d557fdc36430cc0a3b1381e0964e0f89 to your computer and use it in GitHub Desktop.
Save maretekent/d557fdc36430cc0a3b1381e0964e0f89 to your computer and use it in GitHub Desktop.
trim user input
use std::io;
fn main() {
let mut user_input = String::new();
io::stdin()
.read_line(&mut user_input)
.expect("failed to read from stdin");
let trim_input = user_input.trim();
match trim_input.parse::<u32>() {
Ok(i) => println!("user input is integer : {}", i),
Err(..) => println!("user input is not an integer: {}", trim_input)
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment