Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WebUtility.HtmlCode和HttpUtility.HtmlCode不工作?_C#_Asp.net Mvc - Fatal编程技术网

C# WebUtility.HtmlCode和HttpUtility.HtmlCode不工作?

C# WebUtility.HtmlCode和HttpUtility.HtmlCode不工作?,c#,asp.net-mvc,C#,Asp.net Mvc,我有以下不起作用的代码 var sampleText = "Mahindra & Mahindra announced that it is banking on its tractor business in the US and it expects to double its revenues to $1 billion in the ..."; var webDecoded = WebUtility.HtmlDecode(sampleText); var http

我有以下不起作用的代码

var sampleText = "Mahindra & Mahindra announced that it is banking on its tractor business in the US and it expects to double its revenues to $1 billion in the ...";
var webDecoded = WebUtility.HtmlDecode(sampleText);
var httpDecoded = HttpUtility.HtmlDecode(sampleText);
以下是输出:

正确的输出应该是:Mahindra&Mahindra宣布


我在这里做错了什么?

如果您试图获得
Mahindra&Mahindra公布的
,那么正确的输入应该是
Mahindra&;马欣德拉宣布


您有一个额外的
amp
Mahindra&;amp;Mahindra宣布

如果您试图获得
Mahindra&Mahindra宣布
,则正确的输入应该是
Mahindra&;马欣德拉宣布


您有一个额外的
amp
Mahindra&;amp;马欣德拉宣布

代码工作正常。此输入字符串:

"&"
"&"
当HTML解码时,将产生以下输出字符串:

"&"
"&"
因为
&解码为
&

该字符串有一个额外的
amp在其中,它不会解码为任何内容,因为它不是HTML代码。因此,解码器将其视为任何其他文本


该输出字符串可以再次解码,这将使生成的
&进入
&

代码工作正常。此输入字符串:

"&"
"&"
当HTML解码时,将产生以下输出字符串:

"&"
"&"
因为
&解码为
&

该字符串有一个额外的
amp在其中,它不会解码为任何内容,因为它不是HTML代码。因此,解码器将其视为任何其他文本

该输出字符串可以再次解码,这将使生成的
&