ADD STRING AFTER A SPECIFIED STRING

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C# 
C#
 1241  View(s)
Ratings:
Rate this:
Hi Guys!

Say I have the following HTML string

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

I want to add a string in between the <head> tags. So the final HTML string become

<head>
<base href="http://www.minstick.com/images/">
</head>

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

So I have to search for the first occurrence of the <head> string then insert <base href="http://www.mindstick.com/images/"> right after.

How do I do this in C#.

Thanks in advance!
Any help will be appreciated! 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Add string after a specified string

    Hi Ankit!


    You can just do something as following

    myHtmlString.Replace("<head>", "<head><base href=\"http://www.mindstick.com/images/\">");

    Not the most elegant or expandable, but satisfies the conditions of your question.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!