SecurityElement.SearchForTextOfTag(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
依它的標記名稱尋找子項目,並傳回所包含的文字。
public:
System::String ^ SearchForTextOfTag(System::String ^ tag);
public string? SearchForTextOfTag(string tag);
public string SearchForTextOfTag(string tag);
member this.SearchForTextOfTag : string -> string
Public Function SearchForTextOfTag (tag As String) As String
參數
- tag
- String
要在子項目中搜尋的標記。
傳回
第一個子項目的文字內容,這個子項目具有指定標記值。
例外狀況
tag 為 null。
範例
下列程式代碼示範如何使用 SearchForTextOfTag 方法來依其標記名稱尋找子系,並傳回自主文字。 此程式代碼範例是針對 類別提供的較大範例的 SecurityElement 一部分。
string storedDestroyTime =
localXmlElement.SearchForTextOfTag("destroytime");
Dim storedDestroyTime As String = localXmlElement.SearchForTextOfTag("destroytime")
備註
這個方法相當於下列專案:
string SearchForTextOfTag(string tag)
{
SecurityElement element = this.SearchForChildByTag(tag);
return element.Text;
}
Public Function SearchForTextOfTag(ByVal tag As String) As String
Dim element As SecurityElement = MyClass.SearchForChildByTag(tag)
Return element.Text
End Function
使用 XML 時, SearchForTextOfTag("second") 會傳回 「text2」。
<thetag A="123" B="456" C="789"> <first>text1</first>
<second>text2</second></thetag>