Java String.replace not working

后端 未结 1 1138
刺人心
刺人心 2021-01-23 18:03

This is my code.

String x = \"1+√10\";
x = x.replace(\".*\", \"x\");
System.out.println(x);

This should return \"x\" but

1条回答
  •  悲&欢浪女
    2021-01-23 18:32

    String#replace doesn't support regex, use String#replaceAll:

    x = x.replaceAll(".+", "x");
    

    0 讨论(0)
提交回复
热议问题