Easy code: Parse HTML String to get InnerText

Today, I had to get comments, stored in a database, to publish them in a Web Form Application.

These comments were formatted with HTML tags (not well formed) so I needed to parse the data to get only the Inner text.

I developed this piece of code which is very easy … but useful too.

public static string GetInnerHtmltext(string data)
{
  string decode = System.Web.HttpUtility.HtmlDecode(data);
  Regex objRegExp = new Regex("<(.|\n)+?>");
  string replace = objRegExp.Replace(decode, "");
  return replace.Trim ("\t\r\n ".ToCharArray ());
}

Have Fun !!!