2016-01-12 52 views
0

我有一個DIV可以有一個attribut edth_type,我希望能夠通過if比較它的價值。如何按節點排序AgilityPack

我已經看到了其他職位一些人使用

if (string.Compare(node.Attributes["edth_type"].Value, "contenu", StringComparison.InvariantCultureIgnoreCase) == 0) 
{ 
     node.Remove(); 
} 

但事實是,我需要能夠做更多的事情,如:

if(node.Attributes["edth_type"] != contenu) 
{ 
    node.remove 
} 

我如何能做到這一點,我已閱讀msdn文檔有關string.Compare,但不理解它,我想知道,因爲我使用HtmlAgilityPack,如果有一種方法可以做到這一點。

有人能解釋一下string.Compare是可能性(-1,0,1)還是知道一個更好的方法來測試一個attribute在HtmlAgilityPack中?

安裝程序:ASP.NET 4.0,代碼位於C#服務器端。

+1

比較對於排序(因此返回值) - 您可能希望使用'string.Equals(node.Attributes [「edth_type」] .value,「contenu」,StringComparison.InvariantCultureIgnoreCase)'代替 – stuartd

+0

@stuartd在我使用Equals的情況下,它會返回0或1代表「=」或「! =「? – Slayner

+0

Equals返回一個布爾值,所以'true'或'false'是可能的值 – stuartd

回答

0

爲@stuardtd說,這是更好地使用這樣的:

if (string.Equals(node.Attributes["edth_type"].Value, "contenu", StringComparison.InvariantCultureIgnoreCase)==false) 
{ 
     node.Remove(); 
} 

或像這樣:

if (!string.Equals(node.Attributes["edth_type"].Value, "contenu", StringComparison.InvariantCultureIgnoreCase)) 
{ 
     node.Remove(); 
}