Q:

removing space before new line in java

i have a space before a new line in a string and cant remove it (in java).
I have tried the following but nothing works:
strToFix = strToFix.trim();
strToFix = strToFix.replace(" \n", "");
strToFix = strToFix.replaceAll("\\s\\n", "");

A:

myString.replaceAll("[ \t]+(\r\n?|\n)", "$1");

replaceAll takes a regular expression as an argument.  The [ \t] matches one or more spaces or tabs.  The (\r\n?|\n) matches a newline and puts the result in $1.

