Removing Tags

Removing Tags

Removing Tags C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

string company = "<div><p><b><element1>The Inside Corner</element1><element2>, Inc.</element2></b><hr/><br/> Benicia, CA</p></div>";

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using &#58; for colon and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", displayName);
output.RenderEndTag(); //P

output.Write("{0}&#58;&#160;{1}", "Original String", "<b>" + company + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Tags Removed", Sitecore.StringUtil.RemoveTags(company));
output.RenderEndTag(); //Div


Removing Tags C# Web Control Output


Original String: 

The Inside Corner, Inc.

 

Benicia, CA


Tags Removed: The Inside Corner, Inc. Benicia, CA