login about faq

Is there a way in the csv module to force a string to be quoted even though the text is valid? I have an issue where the system that I am sending data to is dropping the leading 0. If I send 01234 in the csv file, they see 1234.

asked Aug 10 at 14:05

emartinson's gravatar image

emartinson
148162032


Yes, just add double-quote chars escaped. For example, in C++:

    CkCsv csv;

csv.put_HasColumnNames(true);

csv.SetColumnName(0,"year");
    csv.SetColumnName(1,"color");
    csv.SetColumnName(2,"country");
    csv.SetColumnName(3,"food");

csv.SetCell(0,0,"2001");
    csv.SetCell(0,1,"red");
    csv.SetCell(0,2,"France");
    csv.SetCell(0,3,"cheese");

csv.SetCell(1,0,"2005");
    csv.SetCell(1,1,"blue");
    csv.SetCell(1,2,"United\r\nStates");
    csv.SetCell(1,3,"\"hamburger\"");

//  Write the CSV to a string and display:
    const char *csvDoc = csv.saveToString();
    printf("%s\n",csvDoc);
link

answered Aug 14 at 20:31

chilkat's gravatar image

chilkat ♦♦
12.5k317361456

edited Aug 14 at 20:32

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×4

Asked: Aug 10 at 14:05

Seen: 381 times

Last updated: Aug 14 at 20:32

powered by OSQA