Replacing escape character?

B

Brett Romero

I have a string with the following XML and need to remove all of the
back slashes

"<ROOT><Person PersonId=\"56102\" /><Person PersonId=\"56104\"
/><Person PersonId=\"71266\" /></ROOT>"

I use

string newstring = cleanXML.Replace(@"\", "");

or

string newstring = cleanXML.Replace("\\", "");

But the back slashes remain. What is needed to remove them?

Thanks,
Brett
 
J

Jon Skeet [C# MVP]

Brett Romero said:
I have a string with the following XML and need to remove all of the
back slashes

"<ROOT><Person PersonId=\"56102\" /><Person PersonId=\"56104\"
/><Person PersonId=\"71266\" /></ROOT>"

I use

string newstring = cleanXML.Replace(@"\", "");

or

string newstring = cleanXML.Replace("\\", "");

But the back slashes remain. What is needed to remove them?

Both of those will remove the backslashes. How are you determining that
the backslashes are there in the first place, and that they're there
afterwards? If it's by looking in the debugger, this may be confusing
you. See
http://www.pobox.com/~skeet/csharp/strings.html#debugger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top