Q:

C# How may i replace \" with "

I am trying to replace \" in a string with ", how may i do that? 
I've tried using replace but i could not find a way to do it. 
Ex: 
string line = "This is a \"sample\" "
string replaced = "This is a "sample" ". 

Thanks. 

A:

Because quotes are used to start and end strings (they are a type of control character), you can't have a quote in the middle of a string because it would terminate the string
string replaced = "This is a "sample" ";
/*
You can see from the syntax highlighting (red) that the string is being
detected as <This is a > and <sample> is black meaning it is detected as 
code (and will cause a syntax error)
*/

In order to put a quote in the middle of the string we escape it (escaping means to treat it as a character literal instead of a control character) using the escape character, which in C# is backslash. 
string line = "This is a \"sample\"";
Console. WriteLine(line);
// Output: This is a "sample"

string literalLine = @"This is a ""sample""";
Console. WriteLine(literalLine);
// Output: This is a "sample"

The @ symbol in C# means I want this to be a literal string (ignore control characters), however quotes still start and end strings so in order to print a quote in a literal string you write two of them "" (that's how the language is designed)

