Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including comma in CSV file

I am currently working on importing data in CSV file. I am stuck over deciding a variable which needs to be added to a field which is comma separated. Below is the data -

 "acNumber","Date","Code"
  12332,123  09/12/2012 1231

This is the desired format. How it actually shows

  "acNumber","Date","Code"
  12332        123   09/12/2012 ...

Actual data being sent is a string & in the format below -

"12332,13321","08/08/2016","1234"

I have tried below the following possible solutions -

1) surrounding my code with quotes as suggested here

""12332,13321""

I have added two double quotes as the value was already covered in quotes.I have tried with single double quotes as well.

2) Use of escape ("\") before comma in final output string

 "12332\,13321"

I have googled over it and still didn't found any solution.Kindly help.

like image 884
Narendra Pandey Avatar asked Oct 20 '25 04:10

Narendra Pandey


1 Answers

If you want to escape your separator which is a comma here you are supposed to put the content between double quotes so if you have 12332,123 you should put "12332,123" in your CSV file.

If you want to escape a content between double quotes you have put it between two new double quotes which gives three double quotes in total so if you have "12332,13321" you should put """12332,13321"""

like image 76
Nicolas Filotto Avatar answered Oct 22 '25 19:10

Nicolas Filotto