title: String Replace: Ignore Whitespace
body: <p>The issue that I am having is the following.</p>
  
  <p>The root cause of my issue is "XML" parsing (XML is in quotes, because in this case, it is not directly XML) and whitespace.</p>
  
  <p>I need to be able to convert this:</p>
  
  <pre><code> "This is a &lt;tag&gt;string&lt;/tag&gt;"
  </code></pre>
  
  <p>into</p>
  
  <pre><code> "This is a {0}"
  </code></pre>
  
  <p>It must be able to handle nested tags, and that sort of thing.  My plan was to use the following to get my replacement text.</p>
  
  <pre><code> var v = XDocument.Parse(string.Format("&lt;root&gt;{0}&lt;/root&gt;", myString),LoadOptions.PreserveWhitespace);
   var ns = v.DescendantNodes();
   var n = "" + ns.OfType&lt;XElement&gt;().First(node =&gt; node.Name != "root");
  </code></pre>
  
  <p>That code returns the first pair of matching tags.  It can handle nesting, etc.  The only real issue is that even with the "PreserveWhitespace" option, carriage returns are getting eliminated.  <code>"\r\n"</code> is converted to just <code>"\n"</code>.  This prevents a match, so:</p>
  
  <pre><code> myString = myString.Replace(n,"{0}");
  </code></pre>
  
  <p>does not work as expected.  So I am trying to come up with a way to get the replacement to work properly, ignoring whitespace, but I don't know how to begin...  Thoughts?</p>