c# - How can I strip any and all HTML tags from a string? -
this question has answer here:
- how can strip html tags string in asp.net? 13 answers
i have string defined so:
private const string refer_to_business = "<pre> (refer business office guidance , explain below circumstances exception policy or attach copy of request)</pre>";
...which has, can see, "pre" tag preserve space prepended verbiage. want to, though, reference string without "pre" tags. easy enough search "<pre>" , "</pre>" , remove them, become tedious every html tag type.
how can i, in c#, strip tags out of string, regardless of whether "<pre>", "<h1>", "<span>", "<aside>" or else?
try regex replacement. pattern matches html tags within string. here
var pattern = @"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>"; var source = "<pre> (refer business office guidance , explain below circumstances exception policy or attach copy of request)</pre>"; regex.replace(source, pattern, string.empty);
Comments
Post a Comment