Farrukh Ahmed
Farrukh Ahmed

Reputation: 493

Remove backslash from the string C#

I have string in which some xml resides.

The string is:

string xmlRead = "<ns0:RequestedAmount xmlns:ns0=\"http://tempuri.org/XMLSchema.xsd\">  <ns0:RequestedAmount></ns0:RequestedAmount>  </ns0:RequestedAmount>" +
                         "<ns0:Response xmlns:ns0=\"http://tempuri.org/XMLSchema.xsd\">  <ns0:Response/> </ns0:Response>" +
                         "<ns0:isValid xmlns:ns0=\"http://tempuri.org/XMLSchema.xsd\">  <ns0:isValid/> </ns0:isValid>";

I have tried this:

string s=xmlRead.Replace(@"\","");
string s=xmlRead.Replace("\"","");
string s=xmlRead.Replace(@"\",string.Empty);

Nothing is working kindly help me out what I am doing wrong here.

Upvotes: 0

Views: 5277

Answers (2)

swapnil chandankar
swapnil chandankar

Reputation: 87

Use following code this will help you.

    string x=@"ABCD\EFG";
    string y=x.Replace(@"\","");

Upvotes: 0

DGibbs
DGibbs

Reputation: 14618

Those backslashes won't actually appear in the final string. They are just escape sequences for the quotes "".

MSDN Escape Sequences

My guess is that you're viewing the string in the debugger which will still show them as unescaped.

Upvotes: 8

Related Questions