replaceAll有$的问题,帮忙看一下,谢谢..
public static void main(String[] args) {
String k= "adasd ";
k=k.replaceAll( "d ", "a$ ");
System.out.println(k);
}
执行后为什么报错呢?
java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at java.lang.String.charAt(String.java:444)
at java.util.regex.Matcher.appendReplacement(Matcher.java:559)
at java.util.regex.Matcher.replaceAll(Matcher.java:661)
at java.lang.String.replaceAll(String.java:1663)
at Test.main(Test.java:15)
Exception in thread "main "
------解决方案--------------------基于正则匹配的 $属于关键字符
所以会有异常