How to Strip (Remove) HTML tag from a String Using ASP.NET C#
Using regular Expressions we can strip HTML Contents from a string. System.Text.RegularExpressions namespace conatin regular expressions in asp.net.
Replaces all occurrences of a pattern defined by a specified regular expressionwith a specified replacement character string, starting at the first character in the input string. Options can be specified to modify matching behavior.
Syntax
1: Regex.Replace(string input, string pattern, string replacement);
2: Regex.Replace(string input, string replacement, int count, int startat);
3: Regex.Replace(string input, string pattern, MatchEvaluator evaluator, RegexOptions options);
Example
string pattern = @"<(.|\n)*?>";
string withOutHtml=Regex.Replace("html content",pattern,string.Empty,RegexOptions options);
3 comments:
It does'nt replace img tag. What to do to replace image tag?
vipul it replace all the html part of the given string.i tested this after that i posted this code snippet.
dont forget to add this on ur code using System.Text.RegularExpressions;
please check this image http://cafekerala.com/makhaaiblogspot/regex.jpg
Post a Comment