Hello I have a code like this:
public string dataToCsv(Dictionary<string, List<string>> data, long qty, string segment)
{
string dateToday = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
string user = Environment.UserName;
var pathToCsv = "C:/Users/" + user + "/Documents/"+ segment + "-" + dateToday + ".csv";
StringBuilder sb = new StringBuilder();
String csv = String.Join(",",
data.Select(d => d.Key));
sb.Append(csv + Environment.NewLine);
for (int i = 0; i < qty; i++) {
String csv1 = String.Join(",",
data.Select(d => string.Join(",", d.Value.Skip(i).Take(1))));
sb.Append(csv1 + Environment.NewLine);
}
System.IO.File.WriteAllText(pathToCsv, sb.ToString());
return pathToCsv;
}
Works pretty fine but when an element value has a comma. That value is separated and lag the columns of the csv. I need if the element has a comma put with them in the csv. Is there any way to do this?
Maybe if I change the separator from the dictionary but don´t know how to do it. My Dictionary has a list of strings.