Welcome to MSDN Blogs Sign in | Join | Help

.net ready !!!

        Maxime Lamure
          MCS France
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 !!!

Posted: Friday, January 26, 2007 3:40 PM by Maxime LAMURE

Comments

Shilpa said:

nice code but how to parse html images ?

my mail address b is shilpakmlthn@yahoo.co.in

# May 25, 2009 4:37 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker