replace all + with -

后端 未结 6 1557
滥情空心
滥情空心 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:16

    If you are not sure about the escape sequence you need to use,

    You could simply do this.

    str = str.replaceAll(Pattern.quote("+"), "-");
    

    This will automatically escape the regex predefined tokens to match in a literal way

提交回复
热议问题