Solved

Remove html tags

Posted on 2015-02-02
5
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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