Solved

Remove html tags

Posted on 2015-02-02
5
257 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 75

Expert Comment

by:käµfm³d 👽
ID: 40584402
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
ID: 40584546
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
ID: 40585447
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
ID: 40586788
Console.WriteLine(System.Net.WebUtility.HtmlDecode(str))

or HttpUtility.HtmlDecode
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40601796
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

14 Experts available now in Live!

Get 1:1 Help Now