std-method
str::strip_prefix
Borrow the rest of the text only when the prefix matches at the beginning. A missing prefix returns None. Expected stdout (not executed): Some("42") true Common mistake: Using replace when only the beginning of the text should be removed.
Formal Syntax & Structure
rust syntaxrust
fn strip_prefix<P: Pattern>(&self, prefix: P) -> Option<&str>Working Example
Example Snippetrust
fn main() { let input = "ID:42"; println!("{:?}", input.strip_prefix("ID:")); println!("{}", input.strip_prefix("name:").is_none());}