+ 1
remove html tags in the string..
I need to remove all HTML tags in the strings expect <p>,<br>,<strong>,<li>,<ol> Please provide a solution. I have tried the code Text = Regex.Replace(Text, "(?i)<(?!p|/p|br|/br|ul|/ul|li|/li|ol|/ol|strong|/strong|b|/b|em|/em|i|/i).*?>", String.Empty); But it will also remove the less than and greater than cases on the string.
2 ответов
+ 2
You could Parse your text in an XmlDocument object, and on the root element call InnerText to extract the text.
+ 1
Hi @Ja Play
your answer is only acceptable for valid HTML Tags only.
But my text has invalid tags also. So give a better solution.
For Example
Text = "<p class = etc> Ponmani <br> some text <p> closed where 5 < 7 and 11 > 7 </p>"
I need this output.
<p>Ponmani <br> some text <p> closed where 5 < 7 and 11 > 7 </p>
But that will remove HTML tags as followed by
<p>Ponmani <br> some text <p> closed where 5 7 </p>