String preCode = "helloi++;world";
String newCode = preCode.replaceAll("i++;", "");
//期望的输出::newCode = "helloworld";
但这并不是用空白替换 i++。
最佳答案
只需使用 replace()
而不是 replaceAll()
String preCode = "helloi++;world";
String newCode = preCode.replace("i++;", "");
或者如果你想要replaceAll()
,应用下面的正则表达式
String preCode = "helloi++;world";
String newCode = preCode.replaceAll("i\\+\\+;", "");
注意:在 replace()
的情况下,第一个参数是字符序列,但在 replaceAll
的情况下,第一个参数是正则表达式
关于java - String replaceAll 不替换 i++;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51703641/