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

1 Answer

0 votes
object Main extends App {
  var s = "Scala- prog$$$$ra-mming! la!ng-uage!"
  
  s = s.replace('!', ' ')
       .replace('$', '*')
       .replace('a', 'A')
       .replace('-', '+')
  
  println(s)
}


   
/*
run:
   
ScAlA+ prog****rA+mming  lA ng+uAge 
   
*/

 



answered Oct 21, 2024 by avibootz
...