title: c# replace string within file
body: <p>String.Replace doesn't seem to work properly when replacing a portion of an HTML file's content. For example, String.Replace replaces <code>&lt;/body&gt;&lt;/html&gt;</code> with <code>blah blah blah &lt;/body&gt;&lt;/html&gt; html&gt;</code>  - notice the second HTML closing tag is not properly closed and therefore shows up when the page is rendered in the browser by the user. </p>
  
  <p>Anyone know why it's not working as intended? </p>
  
  <pre><code>StreamReader sr = fi.OpenText;
  String fileContents = sr.ReadToEnd();
  sr.close();
  fileContents = fileContents.Replace("&lt;body&gt;", "&lt;body onload='jsFx();' /&gt;");
  fileContents = fileContents.Replace("&lt;/body&gt;","blah blah blah &lt;/body&gt;");
  
  StreamWriter sw = new StreamWriter(fi.OpenWrite());
  sw.WriteLine(contents);
  sw.close();
  </code></pre>