Created
August 9, 2020 19:44
-
-
Save LeoBorai/279acfeb82e7ee352f135e54c49f987e to your computer and use it in GitHub Desktop.
Rust - Find and Remove piece of string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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