作者:土土不怕苦_402 | 来源:互联网 | 2022-12-08 15:44
我们正在使用String的replaceAll方法,我们不能替换{在任何字符串中.我们的例子:
试过:
"some { string".replaceAll("{", "other string");
错误如下:
java.util.regex.PatternSyntaxException:发生非法重复
对任何想法开放!也许有一个解决方法?!
1> svdragster..:
使用replaceAll需要正则表达式(正则表达式)
尝试使用replace方法而不是replaceAll
"some { string".replace("{", "other string");
或者使用正则表达式中的特殊字符 \\
"some { string".replaceAll("\\{", "other string");