Remove the escape sequence '\\' from string to convert it to XmlDocument

隐身守侯 提交于 2019-12-05 10:01:38

Use Regex.Unescape method.

String unescapedString = Regex.Unescape(textString);
user3931102

Regex.Unescape doesn't un-escape ". According to the documentation, it does the following:

"..by removing the escape character ("\") from each character escaped by the method. These include the \, *, +, ?, |, {, [, (,), ^, $,., #, and white space characters. In addition, the Unescape method unescapes the closing bracket (]) and closing brace (}) characters."

So the webservice is returning the string with actual backslashes in it? If so, I would say there's a problem with that webservice you're using, but you should be able to get around it by doing this:

xmlStr = xmlStr.Replace("\\\"", "\"");

You can try escaping in verbatim strings

xmlStr= xmlStr.Contains("\\") ? xmlStr.Replace("\\", @"\"") : xmlStr;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!