For the string \" \\n a b c \\n 1 2 3 \\n x y z \" I need it to become \"a b c 1 2 3 x y z\".
\" \\n a b c \\n 1 2 3 \\n x y z \"
\"a b c 1 2 3 x y z\"
Using this regex str.replaceAll(\"(\\s|
This will remove all spaces and newline characters
String oldName ="2547 789 453 "; String newName = oldName.replaceAll("\\s", "");