Archived Forum Post

Index of archived forum posts

Question:

CSV splitting on in string comma.

Jan 29 '16 at 13:14

Hi Matt and everyone,

I am using csv to process a csv data file form my customer. The file is not very large, about 4000 lines. It going well until CSV tried to slpit on a comma within a quoted block. My guess is that because there is a space on both sides of the comma, CSV assumed this was a new cell.

Here is a sample of the data. Please let me know what to do as a work-around.

Thanks, Erik

"...","LIFTING , PULLING OVER TIME","..."
"...","Joe was bailing cardboard , slipped on cardboard and fell","..."

Accepted Answer

I tested using the latest version of Chilkat, and found no problem. Here's my test program:

    CkCsv csv;

const char *testName = "qa_csvCommaProblem";

csv.put_HasColumnNames(false);

bool success = csv.LoadFile2("qa_data/csv/commaProblem.csv","utf-8");
if (!success)
{
printf("%s\n",csv.lastErrorText());
ReturnStatus(testName)
}

printf("NumRows = %d\n",csv.get_NumRows());

printf("%s\n",csv.getCell(0,0));
printf("%s\n",csv.getCell(0,1));
printf("%s\n",csv.getCell(0,2));

printf("%s\n",csv.getCell(1,0));
printf("%s\n",csv.getCell(1,1));
printf("%s\n",csv.getCell(1,2));

ReturnStatus(testName)