std-method

str::strip_suffix

Remove one matching suffix from a borrowed view; otherwise return None. Expected stdout (not executed): Some("report") Common mistake: Using replace when only the ending should be removed.

Formal Syntax & Structure

rust syntaxrust
text.strip_suffix(pattern) -> Option<&str>

Working Example

Example Snippetrust
fn main() {    println!("{:?}", "report.txt".strip_suffix(".txt"));}
Rust Reference