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


i read in .csv file.

the contents of looks this:

1;"final60";"united kingdom";"2013-12-06 15:48:16";

2;"donnyr8";"netherlands";"2013-12-06 15:54:32"; etc

at moment trying remove quotation marks each line using replace method. have attempted doesn't appear anything. although doesn't seem break program in anyway.

try {     string item2;     list<string> list = file.readlines("file.csv").tolist();     foreach (string listline in list)     {          console.write("#  ");          // seperate line new list ;           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 user know went wrong.     console.writeline("the file not read:");     console.writeline(e.message); } 

how can remove quotation marks in each line?

one approach regex, consider pattern:

\" 

regular expression visualization

debuggex demo

it match " in string this:

var s = regex.replace(input, pattern, string.empty); 

here input entire file or 1 line, pattern \", , s resulting string after removal of double quotes.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -