从字符串C#中删除反斜杠 [英] Remove backslash from the string C#

查看:474
本文介绍了从字符串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.

这篇关于从字符串C#中删除反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆