有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

regex Java replaceAll/replace string与美元符号的实例

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"

}

我不明白。我使用了在互联网上能找到的所有替换方法,包括我能找到的所有堆栈溢出。我甚至试过\u0024!怎么了


共 (0) 个答案