user189370
user189370

Reputation:

Converting & to & etc

I want to convert & to &, " to " etc. Is there a function in c# that could do that without writing all the options manually?

Upvotes: 80

Views: 122203

Answers (5)

Don W.
Don W.

Reputation: 560

using System.Web; 
...
var html = "this is a sample & string"; 
var decodedhtml = HttpUtility.HtmlDecode(html);

Upvotes: 9

Matt Hamsmith
Matt Hamsmith

Reputation: 4036

System.Web.HttpUtility.HtmlDecode()

Edit: Note from here that "To encode or decode values outside of a web application, use..."

System.Net.WebUtility.HtmlDecode()

Upvotes: 122

Use the static method

HttpUtility.HtmlEncode

to change & to & and " to ". Use

HttpUtility.HtmlDecode

to do the reverse.

Upvotes: 33

Corredera Romain
Corredera Romain

Reputation: 266

You can use System.Net.WebUtility.HtmlDecode(uri);

Upvotes: 22

RichardOD
RichardOD

Reputation: 29157

Server.HtmlDecode.

Upvotes: 4

Related Questions