最简单两行代码的问题,求救求救!!!关于replaceAll
public class T
{
public static void main(String[] args)
{
String st= "sssss ";
st.replaceAll( "s ", "$ ");
}
}
Exception in thread "main "
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(Unknown Source)
at java.util.regex.Matcher.appendReplacement(Unknown Source)
at java.util.regex.Matcher.replaceAll(Unknown Source)
at java.lang.String.replaceAll(Unknown Source)
at T.main(T.java:7)
------解决方案--------------------st.replaceAll( "s ", "\\$ ");
------解决方案--------------------改成
st.replaceAll( "s ", "\\$ ");
------解决方案--------------------public class T
{
public static void main(String[] args)
{
String st= "sssss ";
System.out.print(st.replaceAll( "s ", "\\$ "));
}
}