Reputation: 25
i'm writing data into a csv file by formatting a string called newline then appending that string to a string builder called csvBill by adding an array of strings called data in the format function
my problem is if the data contains a comma it messes up the cvs file
is there a way that i can keep the comma without it messing the data in the csv file
for examples Chase,Inc
it shows Chase Inc
newline = String.Format("{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},
{13},{14},{15},{16},{17},{18},{19},{20},{21}", data)
csvBill.Append(newline)
after finishing the append
File.WriteAllText("S:\Applications\TI\CustomerBillingData.csv",
csvBill.ToString())
Upvotes: 2
Views: 1323
Reputation: 342
The one way I normally do it and works fine when opening the file in excel is:
newline = String.Format("""{1}"",""{2}"",""{3}"",""{4}""", data)
csvBill.Append(newline)
Upvotes: 3