0

I simply cannot find how to do this. so, I have a String that will be something like this:

do this
then do that
then more of this

and I need to turn this into an array of strings. where every new line is needs to be a separate entry in the array. I need this done so I can process every line or command separately. I can't enter it directly into an array because this is loaded from a text document, and there is some code that removes comments and unnecessary empty lines, and a few more things with the string before it needs to become an array.

thanks in advance!

2 Answers 2

2
String s = "do this\nthen do that\nthen more of this";
String[] split = s.split("\n");
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the quick reply! I really didn't know it was that easy!
1

Try this:

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

1 Comment

Just curious, how does it differ split("\n")? (I'm always looking to learn new regex tricks :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.