How to replace multiple characters in a string with other characters using Rust

1 Answer

0 votes
fn main() {
    let s = String::from("Rust- prog$$$$ra-mming! la!ng-uage!");
    
    let s = s.replace('!', " ")
             .replace('$', "")
             .replace('a', "A")
             .replace('-', "+");
    
    println!("{}", s);
}


      
/*
run:
  
Rust+ progrA+mming  lA ng+uAge 
 
*/
 

 



answered Oct 21, 2024 by avibootz
...