Skip to content

Instantly share code, notes, and snippets.

@samebchase
Created April 16, 2014 19:37
Show Gist options
  • Save samebchase/10924553 to your computer and use it in GitHub Desktop.
Save samebchase/10924553 to your computer and use it in GitHub Desktop.
use std::strbuf::StrBuf;
fn reverse_sentence(sentence: ~str) -> ~str {
let mut buffer = StrBuf::new();
let mut string_vector: Vec<~str> = Vec::new();
for word in sentence.split(' ') {
string_vector.push(word.to_owned());
}
for word in string_vector.iter().rev() {
buffer.push_str(word.clone());
buffer.push_str(" ");
}
buffer.into_owned()
}
fn main() {
println!("{}", reverse_sentence(~"This is a sentence containing words"));
}
// irukandji% ./reverse-sentence
// words containing sentence a is This
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment