How can I convert the value returned by System.getProperty("line.separator"); to its string representation.
For instance, if the value is "\n" I would like to have the string formed by the characters: ['\' + 'n'], if the value is "\r\n" => ['\','r','\','n']does it make sense?
Some very trivial ideas come to my mind, I would like to know different ones.
edit
Doh!!.. after a little thinking ( very little indeed ) I came up with the obvious:
String lineSeparatorRepresentation
= System.getProperty("line.separator").equals("\n")?"\\n":"\\r\\n";
Check out the escapeJava method of Apache Commons Lang’s StringEscapeUtils class. If you don’t want to depend on Commons Lang just for this, see their source code for how they implement it – since the set of possible escapes are so low, it’s just a small lookup table.