Created
February 10, 2018 18:21
-
-
Save maretekent/d557fdc36430cc0a3b1381e0964e0f89 to your computer and use it in GitHub Desktop.
trim user input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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