A Friend in Need is a Friend in Deed.
Become a Member at ITTreats.com !! Share Your invaluable Experience to Fellow Programmers. Signup, Start Blogging and support fellow Techies.

Strip HTML tags ,Script blocks,Forms, style blocks using Regex in C#.net

Many times in Many cases we may come across this problem how to strip HTML Tags,

How to Remove Script Blocks ? How to remove Form Blocks and how to remove Style sheet blocks ?

for those questions here is the simple and best answer

Strip HTML Tags

to Strip the HTML Tags use the following function,

this will removes the HTML tags from the supplied text

public string StripHTML(string str)

{

return Regex.Replace(str, @\”<(.|\\n)*?>\”, string.Empty);
}

Remove Script Blocks

Usually, removing script blocks is some what tough , but the following function will help you in removing script blocks from the supplied text ,

it will replace the all script blocks with a empty string

public string RemoveScriptblocks(string str)
{
return Regex.Replace(str, @\”@\”, string.Empty);
}

In the same way,

Remove Form Blocks

public string RemoveFormblocks(string str)
{

return Regex.Replace(str, @\”@]*?.*?\”, string.Empty);

}

Article Written by : adrevol
( Articles Submitted : 47 Articles Commented : )




One Response to “Strip HTML tags ,Script blocks,Forms, style blocks using Regex in C#.net”


  1. vijay sharma says:

    good

Leave a Reply