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
String myString = inputString.Replace("\"", "\\\"");
and even
String myString = "";
foreach (Char Character in inputString)
if (Character == '"')
myString += "\\\"";
else
myString += Character;
However, I still keep getting the same string back as I received (no backslashes in front of the double quotes).
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.
Does anyone have any ideas on how I can achieve my desired results?
You are using the
+=operator incorrectly.Try this: