-1

I am trying to replace one html tag with another using asp.net.

 string html = rateNode.InnerHtml;
        string newHtml =html.Replace("<dl>", "<tr>").Replace("</dl>", "</tr>");

but it only replace the second part that is

.Replace("</dl>", "</tr>");

it does not replace the first part. the first part is have class attribute. So i have also tried

 string html = rateNode.InnerHtml;
        string newHtml =html.Replace("<dl class='ui-attr-list util-clearfix'>", "<tr>").Replace("</dl>", "</tr>");

but failed. Please tell me what should i do for replacing the first part. Thanks in advance.

saif
  • 123
  • 2
  • 13

1 Answers1

1

Just replace the opening part of the tag.

.Replace("<dl", "<tr")
Keith Rousseau
  • 4,435
  • 1
  • 22
  • 28
  • Would it make more sense to use regex replace to make sure it's exactly `dl`, so that something like (completely made up example) `` wasn't replaced with ``? (Edit: just to be clear, I'm definitely NOT saying that you should use [regex to parse HTML](http://stackoverflow.com/a/590789/930393) but simply check this one instance) – freefaller Aug 24 '15 at 14:45
  • Thanks @Keith Rousseau – saif Aug 24 '15 at 14:52