Reputation: 4023
How can I remove multiple linebreaks from a string so I only get one linebreak if any. For example I have a string with "\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
, how can I turn that into a single '\n'
?
Upvotes: 7
Views: 8220
Reputation: 6369
In Android I managed to remove more than 2 line breaks with this
textPiece = textPiece.replaceAll("\n\n\n+", "\n\n");
Upvotes: 2
Reputation: 159844
You could use:
myString = myString.replaceAll("[\r\n]+", "\n");
Upvotes: 30