Over a million developers have joined DZone.

Silverlight Tip - Managing HTML


Problem: Silverlight 2 & Silverlight 3 do not support HTML, how can I remove the tags?

Solution: Although there are many solutions to this problem, the quickest and most frequently solution I use is a regular expression to remove HTML tags.  The most straightforward example I’ve found is from John Papa’s book Data Driven Services with Silverlight 2


// Remove HTML tags and empty newlines and spaces and leading spaces
string formattedValue = REgex.Replace(value as string, "<.*?>", "");
formattedValue = Regex.Replace(formattedValue, @"\n+\s+", "\n\n");
formattedValue = formattedValue.TrimStart(’ ‘);
fromattedValue = HttpUtility.HtmlDecode(formattedValue);
if(length > 0 && formattedValue.Length >= length)
formattedvalue = formattedValue.Substring(0, length - 1);
return formattedValue;



Published at DZone with permission of Corey Schuman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}