SecurityElement.SearchForTextOfTag(String) 方法

定義

依它的標記名稱尋找子項目,並傳回所包含的文字。

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

要在子項目中搜尋的標記。

傳回

String

第一個子項目的文字內容,這個子項目具有指定標記值。

例外狀況

tagnull

範例

下列程式碼示範如何使用方法, 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>  

適用於