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

swfobject.embedSWF not working in iOS

javascript ios youtube youtube-api swfobject

I'm learning how YouTube player works with Javascript. I have this code because I want to make a video gallery and it works perfectly in any browser (the idea is to switch between videos by the ID)...

Anyway to make a (wrapping) NSTextField write a carriage return upon pressing return key?

objective-c cocoa nstextfield

I want to use a wrapping text field that can potentially contain carriage returns in my app. Is there any way to force the NSTextField object to write a carriage return into the text area instead of

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.