How do I remove the quotation marks from a .csv file?

c#, file, list, replace

Solution

One approach would be with Regex, consider this pattern:

\"

Debuggex Demo

It will match all `"` in the string so you could do something like this:

var s = Regex.Replace(input, pattern, string.Empty);

Here `input` would be the entire file or even just one line, the pattern would be `\"`, and `s` would be the resulting `string` after the removal of those double quotes.

Problem

I read in a .csv file. The contents of which looks like this: 1;"final60";"United Kingdom";"2013-12-06 15:48:16"; 2;"donnyr8";"Netherlands";"2013-12-06 15:54:32"; etc At the moment I am just trying to remove the quotation marks from each line using the `Replace` method. This is what I have attempted which doesn't appear to do anything. Although doesn't seem to break the program in anyway. ``` try { string item2; List<string> list = File.ReadLines("file.csv").ToList(); foreach (string listLine in list) { Console.Write("# "); // seperate up this line into a new list by ; List<string> listItems = listLine.Split(';').ToList(); foreach(String item in listItems) { if (item == "&quot;") { item2 = item.Replace("&quot;", ""); } else { item2 = item; } Console.Write(item2); } Console.WriteLine("\n"); } } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } ``` How can I remove the quotation marks in each line?

Original source