using
System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
#region
strTagLess = regEx.Replace(strTagLess,
ClearHTMLTags
/// <summary>
/// ClearHTMLTags
/// </summary>
/// <param name="strHTML">Html as text (without encoded)</param>
/// <param name="intWorkFlow">
/// An integer that if equals to 0 runs only the RegExp filter
// .. 1 runs only the HTML source render filter
// .. 2 runs both the RegExp and the HTML source render
// .. >2 defaults to 0
/// </param>
/// <returns>Html stripped off text</returns>
/// <remarks>Author: Narendra Tiwari, Date: 06 Feb 2007</remarks>
/// <example>
/// HtmlOperations operations = new HtmlOperations();
/// strFileData = operations.ClearHTMLTags(File.ReadAllText(filePath), 0);
/// </example>
public string ClearHTMLTags(string strHTML, int intWorkFlow)
{
Regex regEx = null;
string strTagLess = string.Empty;try
{
strTagLess = strHTML;//1. "remove html tags"
if (intWorkFlow != 1)
{
//this pattern mathces any html tag
regEx = new Regex("<[^>]*>", RegexOptions.IgnoreCase);"");
//all html tags are stripped
}//2. "remove rouge leftovers"// "or, I want to render the source"
// "as html."
//We *might* still have rouge < and >
//let's be positive that those that remain
//are changed into html characters
if (intWorkFlow > 0 && intWorkFlow < 3)
{
regEx = new Regex("[<]", RegexOptions.IgnoreCase);//matches a single <
strTagLess = regEx.Replace(strTagLess, "<");
regEx = new Regex("[>]", RegexOptions.IgnoreCase);//matches a single >
strTagLess = regEx.Replace(strTagLess, ">");
}//3. return the stripped off text
return strTagLess;
}
catch
{
throw;
}
}
#endregion