当替换HTML文件的内容时,String.Replace
似乎无法正常工作。例如,String.Replace
将 </body></html>
替换为 blah blah blah </body></html> html>
- 请注意第二个HTML结束标记未被正确关闭,因此在用户在浏览器中呈现页面时会显示出来。
有人知道原因吗?
StreamReader sr = fi.OpenText;
String fileContents = sr.ReadToEnd();
sr.close();
fileContents = fileContents.Replace("<body>", "<body onload='jsFx();' />");
fileContents = fileContents.Replace("</body>","blah blah blah </body>");
StreamWriter sw = new StreamWriter(fi.OpenWrite());
sw.WriteLine(contents);
sw.close();
html>
部分... - Nate