小编emh*_*mha的帖子

Java replaceAll/replace字符串与美元符号的实例

public static String template = "$A$B"

public static void somemethod() {
         template.replaceAll(Matcher.quoteReplacement("$")+"A", "A");
         template.replaceAll(Matcher.quoteReplacement("$")+"B", "B");
             //throws java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3
         template.replaceAll("\\$A", "A");
         template.replaceAll("\\$B", "B");
             //the same behavior

         template.replace("$A", "A");
         template.replace("$B", "B");
             //template is still "$A$B"

}
Run Code Online (Sandbox Code Playgroud)

我不明白.我使用了所有可以在互联网上进行替换的方法,包括我可以找到的所有堆栈溢出.我甚至试过了!怎么了?

java regex string replace dollar-sign

3
推荐指数
1
解决办法
4802
查看次数

标签 统计

dollar-sign ×1

java ×1

regex ×1

replace ×1

string ×1