?
Solved

Remove html tags

Posted on 2015-02-02
5
Medium Priority
?
276 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 1000 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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

800 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