Search code examples
c#htmlasp.netdecodeencode

Decode specific HTML tag from Encoded line


I got this Encoded HTML-line:

<b><br /><i><br /><a><br /><br /><br /><br /><br /><br /><br><br /><br /><br /><br /><br /&gt

This is saved in the database.

When I read this from the database, I need to Decode this.

But I only want to decode this tag: <br /&gt (the line contains multiple times this tag).

I looked at this solution, but I didn't understand it well:

C# HtmlDecode Specific tags only

Can anyone give me some tips on how I can solve my problem?

Edit: I need to use Server.HtmlDecode to get breakline between sentences, so ''Replace''-string function won't work.

  1. I'm saving encoded values to the database.
  2. I'm reading the encoded values from the database.
  3. I want to decode only the "&lr;br /&gt"-tag which will result in a breakline
  4. The other tags should stay the same without decoding.

Solution

  • If you just want to decode that tag, it sounds like all you really need is a bog-standard string replace:

    var myString = "<b><br /><i><br /><a><br /><br /><br /><br /><br /><br /><br><br /><br /><br /><br /><br /&gt";
    var outputString = myString.Replace("&lr;br /&gt;", "<br />");