Java (android): How to split a string every two line breaks?
3 answers
First of all, you must exit \
with another \
like this:
string.split("\\n\\n");
Another way is to use the default line separator:
string.split(System.getProperty("line.separator")+"{2}");
or you can try mixing this:
string.split("(\\r\\n|"+System.getProperty("line.separator")+")+");
split
needs RegExp, so you can try options for your problem.
And don't forget that sometimes a newline is not just a character \n
, for Windows files it can be a \r\n
char sequence .
+2
source to share