How to replace a plus character using Java's String.replaceAll method

后端 未结 8 1896
别跟我提以往
别跟我提以往 2020-12-28 11:50

What\'s the correct regex for a plus character (+) as the first argument (i.e. the string to replace) to Java\'s replaceAll method in the String class? I can\'t

8条回答
  •  不思量自难忘°
    2020-12-28 12:34

    String str="Hello+Hello";   
    str=str.replaceAll("\\+","-");
    System.out.println(str);
    

    OR

    String str="Hello+Hello";   
    str=str.replace(Pattern.quote(str),"_");
    System.out.println(str);
    

提交回复
热议问题