Skip to content

Instantly share code, notes, and snippets.

@jpastuszek
Forked from anonymous/playground.rs
Created August 25, 2016 15:56
Show Gist options
  • Save jpastuszek/87c5daf36c35d47749fba41e234c38d2 to your computer and use it in GitHub Desktop.
Save jpastuszek/87c5daf36c35d47749fba41e234c38d2 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
// This code is editable and runnable!
fn main() {
let s = "foo\"bar\"baz\"";
//println!("{}", s.split('"').collect::<Vec<_>>().join("\\\""));
let mut iter = s.split('"').peekable();
loop {
match (iter.next(), iter.peek()) {
(Some(i), Some(_)) => print!("{}\\\"", i),
(Some(i), None) => {
print!("{}", i);
break
}
_ => unreachable!()
}
}
/*
for i in iter {
println!("{:?}", iter.peek());
print!("{}\\\"", i);
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment