Why isn't this text changing?

travisowens

Well-known member
Joined
Feb 11, 2004
Messages
108
Location
Rochester, NY
// What am I not seeing here?

StreamReader sr = new StreamReader("template.html");
string templateMain = sr.ReadToEnd().ToString();
sr.Close();

// Ive tried both ways below, either way nothing happens when I view templateMain

templateMain.Replace("<!-- %%HTMLTITLE%% -->","OIN Intranet");
templateMain = Regex.Replace(templateMain, "<!-- %%HTMLTITLE%% -->", "ON Intranet");
 
C#:
templateMain = templateMain.Replace("<!-- %%HTMLTITLE%% -->","OIN Intranet");

The string functions return a new string rather than modifying the existing string, you just need to assign that to the original string variable.
 
Even when I create a new string, it doesnt contain the change.

string newTemplateMain = templateMain.Replace("<!-- %%HTMLTITLE%% -->","OIN Intranet");
Response.Write(newTemplateMain);


PS: When I view the HTML source I specifically know <!-- %%HTMLTITLE%% --> is in there, heck, I copied it from the file and pasted it into my code.
 
You might use the replace function as PlausiblyDamp used it.
If it dont work... make sure your templateMain as been filled correctly.
 
Actually my code paste was a typo and I was trying templateMain = templateMain.Replace....

I also tried

string newTemplateMain = templateMain.Replace....

Thers something really bizarre going on here.
 
AH HA

Egg in my face, it seems my coworker had the wrong string names so the replace was being performed on the wrong data.

Guess next time I should check the contents of my string and not assume it actually contains what I thought.

ahhh, debugging.
 
Back
Top