Skip to content

Instantly share code, notes, and snippets.

Created November 29, 2015 14:24
Show Gist options
  • Save anonymous/a54ad0f663543228de78 to your computer and use it in GitHub Desktop.
Save anonymous/a54ad0f663543228de78 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
fn main() {
println!("{:?}", substr("abcdef", 2, 4));
}
fn substr(string: &str, start_index: u32, length: u32) -> String {
let mut result: String = String::new();
let index: usize = start_index as usize;
let mut lusize: usize = length as usize;
lusize = string.len() - lusize;
result.push_str(&string[index..lusize]);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment