T
Tim
// what's wrong with this code?
public class TestReplaceAll {
public static void main(String[] args) {
String techName = "O'brien, Jones";
String replacement = "\\'";
System.out.println( techName.replaceAll("[']", replacement) );
System.out.println( techName.replaceAll("[']", "\'" ) );
System.out.println( techName.replaceAll("[']", "\\'" ) );
System.out.println( techName.replaceAll("[']", "\\''" ) );
}
}
// here's the output
O'brien, Jones
O'brien, Jones
O'brien, Jones
O''brien, Jones
// And here's the documentation on the replaceAll function:
replaceAll
public String replaceAll(String regex,
String replacement)Replaces each substring of
this string that matches the given regular expression with the given
replacement.
An invocation of this method of the form str.replaceAll(regex, repl)
yields exactly the same result as the expression
El bugaroo!
TimJowers
public class TestReplaceAll {
public static void main(String[] args) {
String techName = "O'brien, Jones";
String replacement = "\\'";
System.out.println( techName.replaceAll("[']", replacement) );
System.out.println( techName.replaceAll("[']", "\'" ) );
System.out.println( techName.replaceAll("[']", "\\'" ) );
System.out.println( techName.replaceAll("[']", "\\''" ) );
}
}
// here's the output
O'brien, Jones
O'brien, Jones
O'brien, Jones
O''brien, Jones
// And here's the documentation on the replaceAll function:
replaceAll
public String replaceAll(String regex,
String replacement)Replaces each substring of
this string that matches the given regular expression with the given
replacement.
An invocation of this method of the form str.replaceAll(regex, repl)
yields exactly the same result as the expression
El bugaroo!
TimJowers