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( L"destroytime" );
string storedDestroyTime =
localXmlElement.SearchForTextOfTag("destroytime");
Dim storedDestroyTime As String = localXmlElement.SearchForTextOfTag("destroytime")
備註
這個方法相當於下列專案:
String^ SearchForTextOfTag(String^ tag)
{
SecurityElement^ element = this->SearchForChildByTag(tag);
return element->Text;
}
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")
會傳回 "&"。
<thetag A="123" B="456" C="789"> <first>text1</first>
<second>text2</second></thetag>