Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing HTML entities in strings

Tags:

html

c#

encoding

I have text that is retrieved on a linkbutton press:

enter image description here

When I press the button I am getting the following returned:

Test UAT's for release 2.2.0

It looks like HMTL entities are being retrieved. How do I turn these back into normal strings?

like image 964
David Tunnell Avatar asked Oct 30 '13 19:10

David Tunnell


People also ask

How do I remove special characters from a string in HTML?

Your answer function clean($string) { $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. }

How do I remove a string in HTML?

The HTML tags can be removed from a given string by using replaceAll() method of String class. We can remove the HTML tags from a given string by using a regular expression. After removing the HTML tags from a string, it will return a string as normal text.


1 Answers

You don't need to remove the Html entities, actually the string that you are showing here is HTML Encoded so you just need to do Html Decoding to get it in normal form.

For that you have HttpUtility.HtmlDecode method.

string normalString = HttpUtility.HtmlDecode(myEncodedString);

If you are using .NET 4.0 or higher then you can also use WebUtility.HtmlDecode

like image 107
Sachin Avatar answered Oct 13 '22 18:10

Sachin