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代码。因此,解码器将其视为任何其他文本
该输出字符串可以再次解码,这将使生成的&我从中解析这个字符串。源代码似乎编码不正确。我从中解析此字符串。似乎源代码编码不正确。