Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Remove html tags

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
VBdotnet2005
Asked:
VBdotnet2005
  • 2
  • 2
2 Solutions
 
käµfm³d 👽Commented:
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
 
OriNetworksCommented:
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
 
Naitik GamitSoftware DeveloperCommented:
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
 
OriNetworksCommented:
Console.WriteLine(System.Net.WebUtility.HtmlDecode(str))

or HttpUtility.HtmlDecode
0
 
käµfm³d 👽Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now