Diogo Martinho Diogo Martinho - 1 year ago 97
C# Question

Replacing quote character in string c# not working

I am currently trying to replace a string I have in my quote and I have looked for several different solutions but without any success.
this is the string

string line2 = "93100;7;16426;\"PZ16426 1442ab98 (SA) 402A Pedal 1 NO y NC fallo\";\"2016-07-26 08:28:45.000\";\"2016-08-13 10:15:54\"";

And these are my attempts:

line2.Replace(@"\", string.Empty);
line2.Replace(@"\", "");
line2.Replace(@"""", string.Empty);
line2.Replace(@"""", "");

What am I doing wrong?

Answer Source

The replace method does not replace the contents in-place, but returns the string with the characters replaced instead. So instead of

string line2 = "abba";
line2.Replace("a", "e");

you should write

string line2 = "abba";
line2 = line2.Replace("a", "e");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download