I have an input text and a searchterm.
intput = "Hello (A) World" searchTerm = "(A)";
I want to write a method that remove the searchTerm from input.
My code.
public String replaceText(String input, String replacement) {
return input.replaceAll(Pattern.quote(replacement), "");
}
String result = replaceText("Hello (A) World", "(A)");
System.out.println(result);
The result here is "Hello__World" with two whitespace. How I can modify my method to have a result "Hello World". With no extra whitespace left at the position of replacement?