Skip to main content
added 301 characters in body
Source Link
Michael
  • 589
  • 2
  • 7

Depends on what you name "CSV" if you work with really simple files, split(",") may work.

If you should handle arbitrary CSV files, you better read http://ostermiller.org/utils/CSV.html and http://www.csvreader.com/java_csv.php (which I personnaly like less) to understand the size of CSV reading problem.

As a little help (if you need it):

Pattern splitter = Pattern.compile(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");

will handle most of string including strings like "something"",""",""",""another", which covers about 2/3 of CSVs.

Result of split: "something"",""" and """,""another"

Depends on what you name "CSV" if you work with really simple files, split(",") may work.

If you should handle arbitrary CSV files, you better read http://ostermiller.org/utils/CSV.html and http://www.csvreader.com/java_csv.php (which I personnaly like less) to understand the size of CSV reading problem.

Depends on what you name "CSV" if you work with really simple files, split(",") may work.

If you should handle arbitrary CSV files, you better read http://ostermiller.org/utils/CSV.html and http://www.csvreader.com/java_csv.php (which I personnaly like less) to understand the size of CSV reading problem.

As a little help (if you need it):

Pattern splitter = Pattern.compile(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");

will handle most of string including strings like "something"",""",""",""another", which covers about 2/3 of CSVs.

Result of split: "something"",""" and """,""another"

Source Link
Michael
  • 589
  • 2
  • 7

Depends on what you name "CSV" if you work with really simple files, split(",") may work.

If you should handle arbitrary CSV files, you better read http://ostermiller.org/utils/CSV.html and http://www.csvreader.com/java_csv.php (which I personnaly like less) to understand the size of CSV reading problem.