I want to remove " &" from the end of a String
value. If the String doesn't contain " &", I just want the original String/I want nothing to be done to the original String. The strip_suffix
method from &str
does part of that, but it obviously doesn't mutate the provided String. What is the easiest way to strip a certain suffix from a mutable String? Right now, I am stuck with
let old_str = String::from("hello world");
let new_str = match old_str.strip_suffix(" &") {
Some(stripped) => stripped.to_owned(),
None => old_str,
};