2016-02-15 67 views
0

我有一些xml所在的字符串。刪除字符串中的反斜槓C#

的字符串是:

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

沒有什麼工作好心幫助我什麼,我做錯了。

+1

該字符串中沒有反斜槓,我可以看到。我能看到的都是逃脫的字符,例如''''只在字符串中加入''''。 –

+0

但是當我傳遞這個字符串Xml.Create方法時,它給出了路徑中的非法字符的異常,並且當我傳遞沒有這個字符串時它工作正常。 –

+0

Xml.Create是什麼意思?在'XmlDocument'和'XDocument'類中都沒有'Create'方法,我不知道任何剛纔調用'Xml'的.NET Framework類。 –

回答

7

那些反斜槓實際上不會出現在最後一個字符串中。它們只是引號""的轉義序列。

MSDN Escape Sequences

我的猜測是,你在將仍然顯示他們作爲轉義調試器觀看的字符串。

0

使用下面的代碼這將幫助你。

string [email protected]"ABCD\EFG"; 
    string y=x.Replace(@"\",""); 
+0

解釋OP與OP提供的第一個代碼示例的不同之處。你讀過這個問題了嗎? – user1666620

+0

我剛剛在字符串中添加@ –

+0

string xmlRead = @「「+ 」「+ 」「; –