using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
![](/Images/OutliningIndicators/None.gif)
namespace HtmlStripTags
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
class HtmlHelper
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
private static readonly string[][] htmlNamedEntities = new string[][]
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ """, "\"" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "<", "<" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ ">", ">" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ " ", " " },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¡", "¡" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¢", "¢" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "£", "£" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¤", "¤" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¥", "¥" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¦", "¦" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "§", "§" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¨", "¨" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "©", "©" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ª", "ª" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "«", "«" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¬", "¬" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "­", "" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "®", "®" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¯", "¯" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "°", "°" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "±", "±" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "²", "²" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "³", "³" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "´", "´" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "µ", "µ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¶", "¶" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "·", "·" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¸", "¸" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¹", "¹" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "º", "º" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "»", " »" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¼", "¼" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "½", "½" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¾", "¾" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "¿", "¿" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "À", "À" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Á", "Á" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Â", "Â" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ã", "Ã" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ä", "Ä" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Å", "Å" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Æ", "Æ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ç", "Ç" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "È", "È" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "É", "É" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ê", "Ê" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ë", "Ë" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ì", "Ì" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Í", "Í" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Î", "Î" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ï", "Ï" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ð", "Ð" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ñ", "Ñ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ò", "Ò" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ó", "Ó" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ô", "Ô" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Õ", "Õ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ö", "Ö" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "×", "×" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ø", "Ø" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ù", "Ù" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ú", "Ú" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Û", "Û" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ü", "Ü" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ý", "Ý" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Þ", "Þ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ß", "ß" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "à", "à" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "á", "á" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "â", "â" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ã", "ã" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ä", "ä" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "å", "å" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "æ", "æ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ç", "ç" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "è", "è" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "é", "é" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ê", "ê" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ë", "ë" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ì", "ì" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "í", "í" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "î", "î" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ï", "ï" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ð", "ð" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ñ", "ñ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ò", "ò" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ó", "ó" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ô", "ô" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "õ", "õ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ö", "ö" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "÷", "÷" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ø", "ø" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ù", "ù" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ú", "ú" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "û", "û" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ü", "ü" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ý", "ý" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "þ", "þ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ÿ", "ÿ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Œ", "Œ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "œ", "œ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Š", "Š" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "š", "š" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ÿ", "Ÿ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ƒ", "ƒ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ˆ", "ˆ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "˜", "˜" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Α", "Α" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Β", "Β" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Γ", "Γ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Δ", "Δ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ε", "Ε" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ζ", "Ζ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Η", "Η" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Θ", "Θ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ι", "Ι" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Κ", "Κ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Λ", "Λ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Μ", "Μ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ν", "Ν" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ξ", "Ξ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ο", "Ο" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Π", "Π" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ρ", "Ρ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Σ", "Σ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Τ", "Τ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Υ", "Υ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Φ", "Φ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Χ", "Χ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ψ", "Ψ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "Ω", "Ω" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "α", "α" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "β", "β" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "γ", "γ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "δ", "δ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ε", "ε" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ζ", "ζ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "η", "η" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "θ", "θ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ι", "ι" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "κ", "κ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "λ", "λ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "μ", "μ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ν", "ν" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ξ", "ξ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ο", "ο" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "π", "π" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ρ", "ρ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ς", "ς" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "σ", "σ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "τ", "τ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "υ", "υ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "φ", "φ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "χ", "χ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ψ", "ψ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ω", "ω" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ϑ", "ϑ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ϒ", "ϒ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ϖ", "ϖ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ " ", " " },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ " ", " " },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ " ", " " },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‌", "" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‍", "" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‎", "" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‏", "" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "–", "–" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "—", "—" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‘", "‘" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "’", "’" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‚", "‚" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "“", "“" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "”", "”" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "„", "„" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "†", "†" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‡", "‡" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "•", "•" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "…", "…" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‰", "‰" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "′", "′" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "″", "″" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‹", "‹" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "›", "›" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "‾", "‾" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⁄", "⁄" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "€", "€" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ℑ", "ℑ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "℘", "℘" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ℜ", "ℜ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "™", "™" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "ℵ", "ℵ" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "←", "←" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "↑", "↑" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "→", "→" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "↓", "↓" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "↔", "↔" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "↵", "↵" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⇐", "⇐" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⇑", "⇑" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⇒", "⇒" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⇓", "⇓" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⇔", "⇔" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∀", "∀" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∂", "∂" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∃", "∃" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∅", "∅" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∇", "∇" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∈", "∈" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∉", "∉" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∋", "∋" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∏", "∏" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∑", "∑" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "−", "−" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∗", "∗" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "√", "√" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∝", "∝" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∞", "∞" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∠", "∠" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∧", "∧" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∨", "∨" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∩", "∩" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∪", "∪" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∫", "∫" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∴", "∴" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "∼", "∼" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "≅", "≅" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "≈", "≈" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "≠", "≠" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "≡", "≡" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "≤", "≤" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "≥", "≥" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⊂", "⊂" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⊃", "⊃" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⊄", "⊄" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⊆", "⊆" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⊇", "⊇" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⊕", "⊕" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⊗", "⊗" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⊥", "⊥" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⋅", "⋅" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⌈", "⌈" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⌉", "⌉" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⌊", "⌊" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⌋", "⌋" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⟨", "〈" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "⟩", "〉" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "◊", "◊" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "♠", "♠" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "♣", "♣" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "♥", "♥" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "♦", "♦" },
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
new string[]
{ "&", "&" }
};
![](/Images/OutliningIndicators/InBlock.gif)
public static string HtmlStripTags(string htmlContent, bool replaceNamedEntities, bool replaceNumberedEntities)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (htmlContent == null)
return null;
htmlContent = htmlContent.Trim();
if (htmlContent == string.Empty)
return string.Empty;
![](/Images/OutliningIndicators/InBlock.gif)
int bodyStartTagIdx = htmlContent.IndexOf("<body", StringComparison.CurrentCultureIgnoreCase);
int bodyEndTagIdx = htmlContent.IndexOf("</body>", StringComparison.CurrentCultureIgnoreCase);
![](/Images/OutliningIndicators/InBlock.gif)
int startIdx = 0, endIdx = htmlContent.Length - 1;
if (bodyStartTagIdx >= 0)
startIdx = bodyStartTagIdx;
if (bodyEndTagIdx >= 0)
endIdx = bodyEndTagIdx;
![](/Images/OutliningIndicators/InBlock.gif)
bool insideTag = false,
insideAttributeValue = false,
insideHtmlComment = false,
insideScriptBlock = false,
insideNoScriptBlock = false,
insideStyleBlock = false;
char attributeValueDelimiter = '"';
![](/Images/OutliningIndicators/InBlock.gif)
StringBuilder sb = new StringBuilder(htmlContent.Length);
for (int i = startIdx; i <= endIdx; i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i == 4163)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](/Images/OutliningIndicators/InBlock.gif)
// html comment block
if (!insideHtmlComment)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i + 3 < htmlContent.Length &&
htmlContent[i] == '<' &&
htmlContent[i + 1] == '!' &&
htmlContent[i + 2] == '-' &&
htmlContent[i + 3] == '-')
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
i += 3;
insideHtmlComment = true;
continue;
}
}
else // inside html comment
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i + 2 < htmlContent.Length &&
htmlContent[i] == '-' &&
htmlContent[i + 1] == '-' &&
htmlContent[i + 2] == '>')
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
i += 2;
insideHtmlComment = false;
continue;
}
else
continue;
}
![](/Images/OutliningIndicators/InBlock.gif)
// noscript block
if (!insideNoScriptBlock)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i + 9 < htmlContent.Length &&
htmlContent[i] == '<' &&
(htmlContent[i + 1] == 'n' || htmlContent[i + 1] == 'N') &&
(htmlContent[i + 2] == 'o' || htmlContent[i + 2] == 'O') &&
(htmlContent[i + 3] == 's' || htmlContent[i + 3] == 'S') &&
(htmlContent[i + 4] == 'c' || htmlContent[i + 4] == 'C') &&
(htmlContent[i + 5] == 'r' || htmlContent[i + 5] == 'R') &&
(htmlContent[i + 6] == 'i' || htmlContent[i + 6] == 'I') &&
(htmlContent[i + 7] == 'p' || htmlContent[i + 7] == 'P') &&
(htmlContent[i + 8] == 't' || htmlContent[i + 8] == 'T') &&
(char.IsWhiteSpace(htmlContent[i + 9]) || htmlContent[i + 9] == '>'))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
i += 9;
insideNoScriptBlock = true;
continue;
}
}
else // inside noscript block
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i + 10 < htmlContent.Length &&
htmlContent[i] == '<' &&
htmlContent[i + 1] == '/' &&
(htmlContent[i + 2] == 'n' || htmlContent[i + 2] == 'N') &&
(htmlContent[i + 3] == 'o' || htmlContent[i + 3] == 'O') &&
(htmlContent[i + 4] == 's' || htmlContent[i + 4] == 'S') &&
(htmlContent[i + 5] == 'c' || htmlContent[i + 5] == 'C') &&
(htmlContent[i + 6] == 'r' || htmlContent[i + 6] == 'R') &&
(htmlContent[i + 7] == 'i' || htmlContent[i + 7] == 'I') &&
(htmlContent[i + 8] == 'p' || htmlContent[i + 8] == 'P') &&
(htmlContent[i + 9] == 't' || htmlContent[i + 9] == 'T') &&
(char.IsWhiteSpace(htmlContent[i + 10]) || htmlContent[i + 10] == '>'))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (htmlContent[i + 10] != '>')
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
i += 9;
while (i < htmlContent.Length && htmlContent[i] != '>')
i++;
}
else
i += 10;
insideNoScriptBlock = false;
}
continue;
}
![](/Images/OutliningIndicators/InBlock.gif)
// script block
if (!insideScriptBlock)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i + 7 < htmlContent.Length &&
htmlContent[i] == '<' &&
(htmlContent[i + 1] == 's' || htmlContent[i + 1] == 'S') &&
(htmlContent[i + 2] == 'c' || htmlContent[i + 2] == 'C') &&
(htmlContent[i + 3] == 'r' || htmlContent[i + 3] == 'R') &&
(htmlContent[i + 4] == 'i' || htmlContent[i + 4] == 'I') &&
(htmlContent[i + 5] == 'p' || htmlContent[i + 5] == 'P') &&
(htmlContent[i + 6] == 't' || htmlContent[i + 6] == 'T') &&
(char.IsWhiteSpace(htmlContent[i + 7]) || htmlContent[i + 7] == '>'))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
i += 6;
insideScriptBlock = true;
continue;
}
}
else // inside script block
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i + 8 < htmlContent.Length &&
htmlContent[i] == '<' &&
htmlContent[i + 1] == '/' &&
(htmlContent[i + 2] == 's' || htmlContent[i + 2] == 'S') &&
(htmlContent[i + 3] == 'c' || htmlContent[i + 3] == 'C') &&
(htmlContent[i + 4] == 'r' || htmlContent[i + 4] == 'R') &&
(htmlContent[i + 5] == 'i' || htmlContent[i + 5] == 'I') &&
(htmlContent[i + 6] == 'p' || htmlContent[i + 6] == 'P') &&
(htmlContent[i + 7] == 't' || htmlContent[i + 7] == 'T') &&
(char.IsWhiteSpace(htmlContent[i + 8]) || htmlContent[i + 8] == '>'))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (htmlContent[i + 8] != '>')
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
i += 7;
while (i < htmlContent.Length && htmlContent[i] != '>')
i++;
}
else
i += 8;
insideScriptBlock = false;
}
continue;
}
![](/Images/OutliningIndicators/InBlock.gif)
// style block
if (!insideStyleBlock)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i + 7 < htmlContent.Length &&
htmlContent[i] == '<' &&
(htmlContent[i + 1] == 's' || htmlContent[i + 1] == 'S') &&
(htmlContent[i + 2] == 't' || htmlContent[i + 2] == 'T') &&
(htmlContent[i + 3] == 'y' || htmlContent[i + 3] == 'Y') &&
(htmlContent[i + 4] == 'l' || htmlContent[i + 4] == 'L') &&
(htmlContent[i + 5] == 'e' || htmlContent[i + 5] == 'E') &&
(char.IsWhiteSpace(htmlContent[i + 6]) || htmlContent[i + 6] == '>'))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
i += 5;
insideStyleBlock = true;
continue;
}
}
else // inside script block
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i + 8 < htmlContent.Length &&
htmlContent[i] == '<' &&
htmlContent[i + 1] == '/' &&
(htmlContent[i + 2] == 's' || htmlContent[i + 2] == 'S') &&
(htmlContent[i + 3] == 't' || htmlContent[i + 3] == 'C') &&
(htmlContent[i + 4] == 'y' || htmlContent[i + 4] == 'R') &&
(htmlContent[i + 5] == 'l' || htmlContent[i + 5] == 'I') &&
(htmlContent[i + 6] == 'e' || htmlContent[i + 6] == 'P') &&
(char.IsWhiteSpace(htmlContent[i + 7]) || htmlContent[i + 7] == '>'))
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (htmlContent[i + 7] != '>')
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
i += 7;
while (i < htmlContent.Length && htmlContent[i] != '>')
i++;
}
else
i += 7;
insideStyleBlock = false;
}
continue;
}
![](/Images/OutliningIndicators/InBlock.gif)
if (!insideTag)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (i < htmlContent.Length &&
htmlContent[i] == '<')
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
insideTag = true;
continue;
}
}
else // inside tag
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (!insideAttributeValue)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (htmlContent[i] == '"' || htmlContent[i] == '\'')
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
attributeValueDelimiter = htmlContent[i];
insideAttributeValue = true;
continue;
}
if (htmlContent[i] == '>')
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
insideTag = false;
sb.Append(' '); // prevent words from different tags (<td>s for example) from joining together
continue;
}
}
else // inside tag and inside attribute value
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (htmlContent[i] == attributeValueDelimiter)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
insideAttributeValue = false;
continue;
}
}
continue;
}
![](/Images/OutliningIndicators/InBlock.gif)
sb.Append(htmlContent[i]);
}
![](/Images/OutliningIndicators/InBlock.gif)
if (replaceNamedEntities)
foreach (string[] htmlNamedEntity in htmlNamedEntities)
sb.Replace(htmlNamedEntity[0], htmlNamedEntity[1]);
![](/Images/OutliningIndicators/InBlock.gif)
if (replaceNumberedEntities)
for (int i = 0; i < 512; i++)
sb.Replace("&#" + i + ";", ((char)i).ToString());
![](/Images/OutliningIndicators/InBlock.gif)
return sb.ToString();
}
}
}
posted on
2007-09-24 23:28
迷你软件
阅读(
359)
评论()
编辑
收藏
举报