Created
October 2, 2019 08:27
-
-
Save rust-play/c334c9aa1980e78aa710ec9cb1b716a7 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains 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::collections::HashMap; | |
use std::str; | |
fn main() { | |
let s = "a, 100\nb, 200\nw, 20"; | |
let mut m = HashMap::new(); | |
s.split('\n').map(|line| { | |
let v: Vec<_>= line.split(',').map(str::trim).collect(); | |
println!("{:?}", v); | |
if v.len() == 2 { | |
m.insert(v[0], v[1]); | |
} | |
}).collect(); | |
println!("{:?}", m); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment