-2

I have string like the below :

"18","1st",0,"Beattie, Mr Thomson",36.0000,"Cherbourg","Winnipeg, MN","C-6","","","male"

I want to split the string using comma ,ignoring the commas inside the quotes using the split function .

i tried this

line.split("(?:(?:\"\w*\"|\d*)),(?:(?:\"\w*\"|\d*))")

Abhash Kumar
  • 1,168
  • 8
  • 12
  • 2
    What's your question? Surely it's not 'write the code for me'? Presumably you tried this yourself first, can you show your attempt above? – Kon Aug 07 '17 at 17:24
  • use string.split(",") – ja08prat Aug 07 '17 at 17:27
  • 2
    Possible duplicate of [Java: splitting a comma-separated string but ignoring commas in quotes](https://stackoverflow.com/questions/1757065/java-splitting-a-comma-separated-string-but-ignoring-commas-in-quotes) – anvita surapaneni Aug 07 '17 at 17:29
  • This is some example: http://www.mkyong.com/java/how-to-read-and-parse-csv-file-in-java/ – Timothy Truckle Aug 07 '17 at 17:29
  • the duplicate have the answer you can use `str.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*)")` it will gives you a correct result – Youcef LAIDANI Aug 07 '17 at 17:55

1 Answers1

0

There are enough existing modules which allow to import CSV-Files. e.g. https://commons.apache.org/proper/commons-csv/

aschoerk
  • 3,333
  • 2
  • 15
  • 29