Skip to content

Instantly share code, notes, and snippets.

Created August 25, 2016 15:56
Show Gist options
  • Save anonymous/a57ce4294af3ce876d3818a459071d2c to your computer and use it in GitHub Desktop.
Save anonymous/a57ce4294af3ce876d3818a459071d2c 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