c# - Add string after a specified string -


say have following html string

<head>  </head>  <body> <img src="stickman.gif" width="24" height="39" alt="stickman"> <a href="http://www.w3schools.com">w3schools</a> </body>  

i want add string in between <head> tags. final html string become

<head> <base href="http://www.w3schools.com/images/"> </head>  <body> <img src="stickman.gif" width="24" height="39" alt="stickman"> <a href="http://www.w3schools.com">w3schools</a> </body>  

so have search first occurrence of <head> string insert <base href="http://www.w3schools.com/images/"> right after.

how do in c#.

another way of doing this:

string html = "<head></head><body><img src=\"stickman.gif\" width=\"24\" height=\"39\" alt=\"stickman\"><a href=\"http://www.w3schools.com\">w3schools</a></body>"; var index = html.indexof("<head>");  if (index >= 0) {      html = html.insert(index + "<head>".length, "<base href=\"http://www.w3schools.com/images/\">"); } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -