parsing - Best way to parse comma delimeted CSV that include commas that arnt delimeters? [Java] -
parsing - Best way to parse comma delimeted CSV that include commas that arnt delimeters? [Java] -
this question has reply here:
java: splitting comma-separated string ignoring commas in quotes 9 answersi'm trying parse info sets through database. csv files i'm working have info separated commas. there info encompassed quotation marks include commas part of string. how step through each line of info , parse out each info entry given obstacle?
edit: csv parsers not alternative because programme used non csv files. , i'm trying minimize external libraries.
i found issue because of code here parse through quotes:
while(bufferinput.hasnext()){ nextline = bufferinput.nextline(); dataarray = nextline.split(","); for(i = 0; i<colnum;i++){ //try-catch search through dataarray , force sqldata arraylist. try{ if(!dataarray[i].tostring().isempty()){ sqldata.add(dataarray[i].tostring()); } //else if used find empty cells between non empty cells (have test see if opposite of if-statement works) else if(dataarray[i].tostring().equals("")){ sqldata.add(null); } } //catch necessary find cells not @ end of row in text file. catch(arrayindexoutofboundsexception e){ sqldata.add(null); } } }
an illustration of info ,,"ontario, canada",xxxxx.....
locations biggest cause of address contains comma.
so easy fix. had alter split line this:
dataarray = nextline.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
java parsing csv
Comments
Post a Comment