misString= misString.replaceFirst("\n", "");
As the name (and javadoc) of the function indicates, it will only replace the first occurrence ...
misString= misString.replaceAll("\n\r", "");
This replaces all the occurrences, but the problem is the chain you are looking for.
\
is used to mark escape characters ( escape characters ) that represent non-printable symbols using printable symbols. \n
is an escape character representing a new line.
\
is used to "escape" the \
so that it is known to represent the character \
and not that it is a part of an escape character.
So \n
is read as "character \
followed by character n
", not as "new line".
The simplest thing, to eliminate them all independently of the end-of-line coding (varies according to the operating system), would be
misString= misString.replaceAll("(\n|\r)", "");
Another option is to use System.getProperty("line.separator")
that directly gives you the value of the line separator used by the operating system:
misString= misString.replaceAll(System.getProperty("line.separator", ""));