Hey, I have a function that replaces a string within a file:

public static void WebPage(int gradeA, int gradeB, int gradeC, int gradeD, int gradeE, int gradeF)
{
    // read the HTML file
   TextReader webpage = new StreamReader ("/Users/Desktop/Assignment/webpage.html");
   string LookUp;
			
   while ((LookUp = webpage.ReadLine()) != null)
   { 
	  string replace = "var grade1 = \"\"";
	  string replaceWITH = "var grade1 = \"" + gradeA + "\"";
				
	  string str = LookUp.Replace (replace, replaceWITH);
				
				
   }
}

But it doesn't write to the file? But it will display on console window? I have tried to include the TextWriter function but it will just clear the whole HTML.

Any ideas?

It doesn't write to the file because you have no write statement in there anywhere. You'll need to open another file and write out each of the lines your read in.

Your code is reading the line, replaces the string, but doesn't write the new string back into the file. Half way there :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.