Solved

Remove html tags

Posted on 2015-02-02
5
245 Views
Last Modified: 2015-02-10
How can return a string without html tags ( , @amp; etc), I think. Right now, it returns
HB HOSPITAL & MEDICAL CENTER instead of HB HOSPITAL & MEDICAL CENTER.
0
Comment
Question by:VBdotnet2005
  • 2
  • 2
5 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
What is the context here? Is this an ASP.NET application? If so, the runtime should be handling the decoding of that value for you. If this is something else, like a console application, then you have a couple of different options. You could bring in System.Web and its utilities, but that library is massive, so it may not be worth having it just for this task. You could manually do a replace on the offending string--a little clunky, but workable. There are probably other libraries that are smaller than System.Web which would also perform decoding.
0
 
LVL 17

Expert Comment

by:OriNetworks
Comment Utility
As kaufmed mentioned, context is key here so if we have an example of how it is being used we can give a better response. For example, if you are viewing HTML source code and it says HB HOSPITAL & MEDICAL CENTER  then that is as it should be and it should automatically be rendered on the page as HB HOSPITAL & MEDICAL CENTER  by the browser. There are also methods such as HtmlDecode and HtmlEncode which can take unsafe characters and swap their values for storage/retrieval to enhance security of your application but these should be used carefully to make sure you aren't rendering text in an unsafe way.
0
 
LVL 8

Accepted Solution

by:
Naitik Gamit earned 250 total points
Comment Utility
C# program that tests HTML removal
using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
      const string html = "<p>There was a <b>.NET</b> programmer " +
          "and he stripped the <i>HTML</i> tags.</p>";

      Console.WriteLine(HtmlRemoval.StripTagsRegex(html));
      Console.WriteLine(HtmlRemoval.StripTagsRegexCompiled(html));
      Console.WriteLine(HtmlRemoval.StripTagsCharArray(html));
    }
}


Output:
There was a .NET programmer and he stripped the HTML tags.
There was a .NET programmer and he stripped the HTML tags.
There was a .NET programmer and he stripped the HTML tags.
0
 
LVL 17

Assisted Solution

by:OriNetworks
OriNetworks earned 250 total points
Comment Utility
Console.WriteLine(System.Net.WebUtility.HtmlDecode(str))

or HttpUtility.HtmlDecode
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Interesting choice of answer selection, seeing as how the "accepted" answer refers to a few magical methods that aren't actually demonstrated anywhere. The "assisted" solution would have made more sense to be the actual answer.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now