5

I have tried using string.split("\n\n") but it does not work. Anyone has any solution? thanks in advance

0

3 Answers 3

4

First of all you should escape the \ with another \ like this:

string.split("\\n\\n"); 

Another way is using system default line separator:

string.split(System.getProperty("line.separator")+"{2}"); 

or you can try mix this:

string.split("(\\r\\n|"+System.getProperty("line.separator")+")+"); 

split need RegExp, so you can try variants for your problem.

And don't forget that sometimes new line is not only \n symbol, for Windows files it can be \r\n char sequence.

Sign up to request clarification or add additional context in comments.

1 Comment

Three years later. So helpful!
2

You should escape the \ with another \ so try :-

string.split("\\n\\n"); 

Comments

1

Try using the escape sequence \:

string.split("\\n\\n"); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.