And*_*Guy 8 java string replaceall str-replace
String preCode = "helloi++;world";
String newCode = preCode.replaceAll("i++;", "");
Run Code Online (Sandbox Code Playgroud)
//期望的输出:: newCode = "helloworld";
但这并不是用空白取代i ++.
只是用replace()而不是replaceAll()
String preCode = "helloi++;world";
String newCode = preCode.replace("i++;", "");
Run Code Online (Sandbox Code Playgroud)
或者如果您愿意replaceAll(),请应用以下正则表达式
String preCode = "helloi++;world";
String newCode = preCode.replaceAll("i\\+\\+;", "");
Run Code Online (Sandbox Code Playgroud)
注意:在replace()第一个参数的情况下是一个字符序列,但在replaceAll第一个参数的情况下是正则表达式
| 归档时间: |
|
| 查看次数: |
233 次 |
| 最近记录: |