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
Post a Comment