With the following code you can remove a line from a textfile (web.config). If the string is within a line the line will be removed.
[code:c#]
string configFile = @"C:\dev\web.config";
List<string> lineList = File.ReadAllLines(configFile).ToList();
lineList = lineList.Where(x => x.IndexOf("<!--") <= 0).ToList();
File.WriteAllLines(configFile, lineList.ToArray());
[/code]