How to replace multiple words in a single string in Java?

前端 未结 9 2144
眼角桃花
眼角桃花 2020-12-11 17:09

I\'m writing a program that will replace multiple words in a single string. I\'m using this code but it is replacing word but giving result in two different lines. I want

9条回答
  •  隐瞒了意图╮
    2020-12-11 17:15

    Now you can use StringUtils in commons-lang3 package.

    
    
      org.apache.commons
      commons-lang3
      3.7
    
    

    Code like below:

    strOutput = StringUtils.replaceEach(inString, new String[]{"call me", "as soon as possible"}, new String[]{"cm", "asap"});
    

提交回复
热议问题