Smart little helper to clean HTML based strings for [WPDEV] and [WIN8DEV]

I thought I would share this small little class I created to clean out HTML based strings into readable strings. The class is both usable for your Windows Phone app as well as your Windows 8 app.

If you use cloud based or internet data, often strings contain “–” or “–” instead of their intended letter, like you can see on this image:


The method uses Regex to replace all the wrong signs and clean out all of the unwanted signs. You can also add more to that if you need to replace wrong letters.

class CleanHTML
        public static string RemoveEncoding(string text)
                string temp="";

                temp = 
                    Replace("–", "-").
                    Replace(" ", " ").
                    Replace("’", "'").
                    Replace("&", "&").
                    Replace("&", "&").
                    Replace(""", """).
                    Replace("'", "'").
                    Replace("…", "...").
                    Replace("—", "—").
                    Replace("–", "-").
                    Replace("“", "“").
                    Replace("”", "”").
                    Replace("’", "'").
                    Replace(" ", " ").
                    Replace(">", ">").
                    Replace("”", """).
                    Replace("“", """).
                    Replace("&lt;", "<").
                    Replace("&#215;", "×").
                    Replace("&#8242;", "′").
                    Replace("&#8243;", "″").
                    Replace("&#8216;", "'"),
                    "<[^<>]+>", "");

                return temp;
                return "";


As we created a class for this little helper, you can call it from everywhere within you app to clean out the string. Here is one example I am using:

 item.title = CleanHTML.RemoveEncoding(item.title);

After calling this method, your string is plain text:

Screenshot (17)

I hope this post will be helpful for some of you.

Happy coding!

Posted by msicc

.NET Dev at day & night, Geek. Father of 2 teenagers, husband of a fantastic wife. Founder of MSiccDev Software Development. Opinions are mine.