.Net Core System.Web.HttpUtility.HtmlDecode not working when the "&" symbol is there

1.6k views Asked by At
string x = "&Microsoft<?xml version=";
string y = System.Web.HttpUtility.HtmlDecode(x);
Console.WriteLine(y);
Console.ReadLine();

Now the y value is &Microsoft<?xml version=

In this case the web.httputility.htmldecode not working

I am expecting result is &Microsoft<?xml version=

Please reply if there is answer for this.

1

There are 1 answers

6
tontonsevilla On

The code looks good. Upon testing it on my local. I got what your expected result.

enter image description here

UPDATE
For .Net Core, it still the same code but rather remove the unnecessary '&' on the first character of the string. Because it is forbidden to use ampersand without any related url encoding version

eg: '&lt;' = '<'

You can check the code behind for .net core implementation of HtmlEncoder.cs

I hope it helps. Happy coding.