How to remove the last occurrence of a character from a string in Rust

1 Answer

0 votes
fn main() {
    let mut str = String::from("scala c# c python c++ java rust");

    if let Some(index) = str.rfind('c') {
        str.replace_range(index..index + 1, "");
    }

    println!("{}", str);
}



  
/*
run:

scala c# c python ++ java rust

*/

 



answered Sep 8, 2024 by avibootz
...