staticvoid ck(String[] x, String[] ans) throws Exception { if (x.length != ans.length) thrownew Exception("Test failed"); for (int i = 0; i < x.length; i++) { if (!x[i].equals(ans[i])) thrownew Exception("Test failed");
}
}
staticvoid testLiteralReplacement() throws Exception { // Test straightforward replacement
String data = "abcdefghi";
String result = data.replace("def", "abc"); if (!result.equals("abcabcghi")) thrownew Exception("Test failed");
// Test replacement with target that has metacharacters
data = "abc(def)?ghi";
result = data.replace("(def)?", "abc"); if (!result.equals("abcabcghi")) thrownew Exception("Test failed");
// Test replacement with replacement that has metacharacters
data = "abcdefghi";
result = data.replace("def", "\\ab$c"); if (!result.equals("abc\\ab$cghi")) thrownew Exception("Test failed");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.