Home > DeveloperSection > Forums > Add string after a specified string
Ankit Singh

Total Post:341

Points:2389
Posted on    May-13-2013 2:43 AM

 C# C# 
Ratings:


 1 Reply(s)
 840  View(s)
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! 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-13-2013 9:30 AM

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.

Don't want to miss updates? Please click the below button!

Follow MindStick