Silverlight Tip - Managing HTML
Join the DZone community and get the full member experience.Join For Free
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);
Published at DZone with permission of Corey Schuman, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.