public static class HTMLTextHelper
{
public static string RemoveHtmlTags(string html)
{
int pos = 0;
StringBuilder builder = new StringBuilder();
while (pos < html.Length)
{
if (html[pos] == '<')
{
pos = SkipTag(html, pos);
builder.Append(' ');
}
else builder.Append(html[pos++]);
}
return builder.ToString();
}
private static int SkipTag(string html, int pos)
{
pos++;
while (pos < html.Length)
{
if (html[pos] == '"' || html[pos] == '\'')
pos = SkipString(html, pos);
else if (html[pos++] == '>')
break;
}
return pos;
}
private static int SkipString(string html, int pos)
{
char quote = html[pos++];
while (pos < html.Length)
{
if (html[pos++] == quote)
break;
}
return pos;
}
}
Software consultant, Developer, Codder : SharePoint, Office 365, ASP.NET, MVC, SharePoint, Javascript, JQuery, Ember JS, Angular JS, Entity Framework, Linq, HTML5, DotnetNuke, codding philosophy, blogger 7+ experience in codding and developing web applications, Code 4 Help..
27 October 2012
Remove HTML tags from HTML markup string
Subscribe to:
Comments (Atom)