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");
1
  • thanks for the quick reply! I really didn't know it was that easy! Commented Apr 3, 2012 at 9:10
1

Try this:

string.split("(?m)\n");
1
  • Just curious, how does it differ split("\n")? (I'm always looking to learn new regex tricks :) Commented Apr 4, 2012 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.