replace all + with -

后端 未结 6 1466
滥情空心
滥情空心 2021-01-29 06:24

I am trying to replace a + character into a hyphen I have in my string.

String str = \"word+word\";
str.replaceAll(\'+ \', \'-\');
         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 07:05

    `replaceAll´ is for regular expressions and strings are immutable. Use:

    str = str.replace("+", "-");
    

    instead...

提交回复
热议问题