Replace " with \" in C# String
<p>I need to take a string that was originally read in from a text file and prepend a backslash to any and all double quotes found in the string. I tried</p>

<pre><code>String myString = inputString.Replace("\"", "\\\"");
</code></pre>

<p>and even</p>

<pre><code>String myString = "";
foreach (Char Character in inputString)
    if (Character == '"')
        myString += "\\\"";
    else
        myString += Character;
</code></pre>

<p>However, I still keep getting the same string back as I received (no backslashes in front of the double quotes).</p>

<p>In my example, one value of inputString would show up in the debugger as "div id="loader"", and I want the resulting myString to be "div id=\"loader\"" as seen in the debugger.</p>

<p>Does anyone have any ideas on how I can achieve my desired results?</p>
