Friday 30 December 2016

c# remove string with quotes from string




I have a string, containing XML namespace, and I cant seem to remove this part



xmlns="http://www.rar.org/xyz/"



I've tried



return textWriter.ToString().Replace(@"xmlns="http://www.rar.org/xyz/"", "");


but this does not compile.


Answer



You need to escape the string. Since you are providing a verbatim string literal (by using the @), you need to use two quotes to escape it:




return textWriter.ToString().Replace(@"xmlns=""http://www.rar.org/xyz/""", "");

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...