I am sent an XML string that I'm trying to parse via an XmlReader and I'm trying to strip out the \"
characters.
I've tried
.Replace(@"\", "")
.Replace("\\''", "''")
.Replace("\\''", "\"")
plus several other ways.
Any ideas?
This question is related to
c#
replace
special-characters
Try it like this:
Replace("\\\"","");
This will replace occurrences of \"
with empty string.
Ex:
string t = "\\\"the dog is my friend\\\"";
t = t.Replace("\\\"","");
This will result in:
the dog is my friend
\ => \\ and " => \"
so Replace("\\\"","")
Where do these characters occur? Do you see them if you examine the XML data in, say, notepad? Or do you see them when examining the XML data in the debugger. If it is the latter, they are only escape characters for the "
characters, and so part of the actual XML data.
In .NET Framework 4 and MVC this is the only representation that worked:
Replace(@"""","")
Using a backslash in whatever combination did not work...
Replace(@"\""", "")
You have to use double-doublequotes to escape double-quotes within a verbatim string.
Source: Stackoverflow.com