how to remove the \n, \t and spaces between the strings in java?
+3
A:
Use String.replaceAll with a regular expression to remove all whitespace:
s = s.replaceAll("\\s+", "");
Mark Byers
2010-03-17 10:13:37
Ah, come on, Mark, you even go as far as removing the fun of those annoying RTFM questions.
Riduidel
2010-03-17 10:14:32
+6
A:
str.replaceAll("\\s+", "");
\s A whitespace character: [ \t\n\x0B\f\r]
java.util.regex.Pattern
has all the predefined classes.
Bozho
2010-03-17 10:14:23
But note that `\\n+\\t+` only matches new lines followed by tabs. Probably `[\t\n]+` is meant...
Bart Kiers
2010-03-17 10:45:24