the newline symbol \n is causing me a bit of trouble when i try to detect and replace it: This works fine:
String x = "Bob was a bob \\n";
String y = x.replaceAll("was", "bob");
System.out.println(y);
butt this code does not give the desired result
String x = "Bob was a bob \\n";
String y = x.replaceAll("\n", "bob");
System.out.println(y);
"Bob was a bob \\n"
becomes literally Bob was a bob \n
There is no newline to replace in the input string. Are you trying to replace a newline character or the escape sequence \\n
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With