我試圖替換包含字符「$」的子字符串。我很高興聽到它爲什麼沒有這樣工作,以及它會如何工作。替換子字符串(replaceAll)解決方法
感謝, USER_UNKNOWN
public class replaceall {
public static void main(String args[]) {
String s1= "$foo - bar - bla";
System.out.println("Original string:\n"+s1);
String s2 = s1.replaceAll("bar", "this works");
System.out.println("new String:\n"+s2);
String s3 = s2.replaceAll("$foo", "damn");
System.out.println("new String:\n"+s3);
}
}
這是什麼打印出來的? '$ foo - 這個工程 - bla'? – Entity 2010-11-05 12:32:30
可能重複[反斜槓問題與String.replaceAll](http://stackoverflow.com/questions/1701839/backslash-problem-with-string-replaceall) – McDowell 2011-05-26 08:37:02