I am trying to write a List of type string to a csv file and I want any string values to be enclosed in double quotes when written to the file. This certainly seems like a very basic problem, but I am not sure why I am struggling with this. I really must be drunk right now. Appreciate any help on this.
Here is a dumbed down version of what I am trying :
using System.Text;
string myString1 = string.Empty;
string myString2 = string.Empty;
List<string> myList = new List<string>();
StringBuilder sb = new StringBuilder();
//Assign value to myString1 variable, Note: object.Text returns a string value
myString1 = object.Text ;
myString2 = "Hello World";
myList.Add(myString1);
myList.Add(myString2);
sb.AppendLine(string.Join(",", myList));
File.WriteAllText(@"C:\Test.csv", sb.ToString());
Note : object.Text may also contain one or more double quote within the text in some instances. E.g. Table 1/4"" x 1/4""
Expected output : if myString1 was set as Hello World then
Output: "Hello World", "Hello World"