I am looking for a proper and robust way to find and replace all newline or breakline chars from a String independent of any OS platfo
newline
breakline
String
This seems to work well:
String s = "This is a String\nand all newline chars\nshould be replaced in this example."; System.out.println(s); System.out.println(s.replaceAll("[\\n\\r]+", "\\\\n"));
By the way, you don't need to catch exception.