Java split string at “,” and end of line

I have some data that looks like this:

2000-01-05,5.15,5.25,5.05,5.18,42500,5.03
2000-01-04,5.86,5.94,4.99,5.38,56700,5.23
2000-01-03,5.86,5.92,5.59,5.80,84600,5.64

Now I do want to split the string at the "," and at the end of the line. I tried it like this:

String[] results = file.split(",");

This works fine, but when I try this:

String[] results = file.split(",||\\n+");

The whole thing gets messed up, I hope you can help :)

Answers


You can use a better way:

String[] results = a.split(",|"+System.getProperty("line.separator")+"+");

Because the line separator changes between OS..


Try this:

String[] results = file.split(",|\\n+");

Need Your Help

Sharing menu bar between activities

android button android-activity menu share

I have a menu bar on my app, that I need to share between 5 of my activities. My menu bar (= 5 buttons allowing to switch between activities) has exactly the same UI and the same behavior for any

Expanding a shortened url to its original full length url in java

java url urlconnection

I'm attempting to take a shortened url and expand it out to its original full length url in a string format in java. I've been able to track down a tutorial online, however I'm unable to get this to