Originally posted by Carl Pettersson:
A line break is represented as the character combination '\n'. . .
Not quite. That is operating-system dependent. '\n' is a char literal for the linefeed character (0x000a) commonly called newline.
There is also the carriage return character (0x000d, I think) which can be represented by the '\r' char literal.
As far as I remember, Windows uses "\r\n" for line ends, *nix (Unix, Linux, etc) uses '\n' and OS/X (Mac) uses '\r'.
Also what appears as the 1st argument to String#replaceAll is a regular expression as a String. Go through the
Java Tutorial about regular expressions, and
you should find it quite easy to work out how to create a regular expression which matches line-end characters. Find the
JFlex manual; it has a comprehensive list of potential line-end characters in.
There does not (unfortunately) appear to be a Character#isLineEnd method.
You can find the line-end combination for your computer with the System#getProperty method; I think it is called "line.separator", but you can get an array or Properties with the System#getProperties method and iterate through the array to get the names and check whether that is correct. You will have to cast each char to an int to be able to see their values, otherwise the line end looks like this:
Good luck with it