by
1
6
283k
2
Top 1% !
Popular
Pearl of Wisdom
Easy-to-find
Tuned
OpenSource
Popularity: 4210th place

Published on:

.NETFramework4.0
Architecturex86_64
BrowserAll
ClassNameWebUtilities
Extension.cs
InputName0pageString
InputName1tagName
InputType0string
InputType1string
LanguageCSharp
LicenseMIT_X11
MethodNameRemoveHtmlTag
OSWindows
OutputTypestring
Windows VersionWindows7

Remove HTML tags from text

Removes the given tag (and all its content) from the specified text.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/215953/Remove-HTML-tags-from-text?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
static public string RemoveHtmlTag(string pageString, string tagName) { string output = pageString; int exprIni = 0; int firstChar = 0; int lastChar = 0; // find html element exprIni = output.IndexOf("<" + tagName, 0, output.Length, StringComparison.InvariantCultureIgnoreCase); while (exprIni >= 0) { // extract the html firstChar = exprIni; // find <tag ... /> lastChar = output.IndexOf("/>", (firstChar + 1)) + 1; int nextCloseTag = output.IndexOf('>', (firstChar + 1)); // closed with </tag> marker.. if ((lastChar <= 0) || (nextCloseTag < lastChar)) { // find </tag> lastChar = output.IndexOf("</" + tagName, (firstChar + 1), (output.Length - firstChar - 1), StringComparison.InvariantCultureIgnoreCase); lastChar = output.IndexOf('>', (lastChar + 1)); } if ((firstChar < 0) || (lastChar <= 0) || (firstChar == lastChar)) return output.Substring(0, firstChar); else { output = String.Format("{0} {1}", output.Substring(0, firstChar).Trim(), output.Substring((lastChar + 1), (output.Length - lastChar - 1)).Trim()); } exprIni = output.IndexOf("<" + tagName, 0, output.Length, StringComparison.InvariantCultureIgnoreCase); } return output; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus