How to replace a html string?

Posted on 2008-11-06
Last Modified: 2013-12-17

When I read an upload html file from an email program and send to the recipient, I need to replace a html string insides it

<a href=""><img src="" border="0" valign="top"></a>

<a href="''"><img src="" border="0" valign="top"></a>

So that people can click the button to reply and confirm.

Here is the code:

public string SqlEncode(string inStr)
            inStr = inStr.Replace("<a href=""><img src="" border="0" valign="top"></a>", "<a href="'"><img src="" border="0" valign="top"></a>
            return inStr;

But, it does not work.

There are several img links like
img src=""
img src=""
img src=""

Or, I should add \ before all " ?

Please advise
Question by:techques
    LVL 4

    Accepted Solution

    If you want to do it that what then why not just do this:
    inStr = inStr.Replace(@"<a href="""">", "<a href=\"\">");

    You would be better off using a regex to take into account any variations etc.

    Author Comment

    because there are many
    <a href="""">

    it will replace all with the same url.
    there is no id for each  <a href=""""> tag
    LVL 4

    Expert Comment

    Then you are better off using regular expression matching and running it against a dictionary using the URL as the key and the e-mail address as the value.  Could end up very messy though...

    Author Comment

    what is the code?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now