从字符串C#中删除反斜杠

问题描述:

我有一些xml所在的字符串。

I have string in which some xml resides.

字符串是:

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>";

我已经尝试过:

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.

那些反斜杠实际上不会出现在最终字符串中。它们只是引号 的转义序列。

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

MSDN转义序列

我的猜测是,您正在调试器中查看字符串,仍将其显示为未转义。

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