Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi
I am currently trying to export data from my database to a CSV file.

The problem i am having is i have a description field which the users sometimes enter , in the description(e.g. "this is my description,test")

so when i do my export it is creating a new field when the , is added in the Description

is it posible for me to keep the , in the description if so how?
Posted

Yes: CSV allows for that: just surround the data with double quotes:
123,"this has no problem","this would, though", 456

Depending on what you are using to create the CSV file it should do it automatically for you, but if you are generating them yourself, then don't forget to process double quotes in user input to double-double quotes!
123,"this has no problem","this ""would"", though", 456
 
Share this answer
 
Comments
isi19 13-Mar-14 8:39am    
Thanks
OriginalGriff 13-Mar-14 8:44am    
You're welcome!
If you chose the comma as delimiter for your CSV file, then you have several options to circumvent your problem :

1) Use another delimiter for your CSV file (for example, tabulation ("\t"), semicolon (";"), etc.).

2) Enclose your fields between double-quotes; this way, the comma will be recognized as an internal member of the string, rather than as a delimiter.

Hope this helps.
 
Share this answer
 
v3
Comments
isi19 13-Mar-14 8:39am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900