Over a million developers have joined DZone.

Silverlight Tip - Managing HTML

DZone 's Guide to

Silverlight Tip - Managing HTML

· ·
Free Resource

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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}