Skip to content

Instantly share code, notes, and snippets.

@LeoBorai
Created August 9, 2020 19:44
Show Gist options
  • Select an option

  • Save LeoBorai/279acfeb82e7ee352f135e54c49f987e to your computer and use it in GitHub Desktop.

Select an option

Save LeoBorai/279acfeb82e7ee352f135e54c49f987e to your computer and use it in GitHub Desktop.
Rust - Find and Remove piece of string
fn main() {
const NAMESPACE_LENGTH: usize = 9;
let path = "/api/v1/catalog/GetNames";
// find index of catalog namespace
match path.find("/catalog/") {
Some(index) => {
let unused = NAMESPACE_LENGTH + index;
println!("found at {}", index);
println!("func is: {}", &path[unused..])
// found at 7
// func is: GetNames
},
None => println!("Not found!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment