Delete multiple rows

How can I remove multiple rows from a row, so I only get one row, if any. For example, I have a line with "\r\n\r\n\r\n\r\n\r\n\r\n\r\n" , how can I turn this into one '\n' ?

+4
source share
2 answers

You can use:

 myString = myString.replaceAll("[\r\n]+", "\n"); 
+21
source

On Android, I managed to remove more than two line breaks with this

 textPiece = textPiece.replaceAll("\n\n\n+", "\n\n"); 
+1
source

All Articles