Per Mausklick bewerten und Feedback geben
MSDN
MSDN Library
.NET Entwicklung
System
String-Klasse
String-Methoden
 Contains-Methode
Alle reduzieren/Alle erweitern Alle reduzieren
Diese Seite ist spezifisch für
Microsoft Visual Studio 2005/.NET Framework 2.0

Andere Versionen stehen ebenfalls zur Verfügung für:
.NET Framework-Klassenbibliothek
String.Contains-Methode

Hinweis: Diese Methode ist neu in .NET Framework, Version 2.0.

Gibt einen Wert zurück, der angibt, ob das angegebene String-Objekt in dieser Zeichenfolge vorkommt.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Visual Basic (Deklaration)
Public Function Contains ( _
    value As String _
) As Boolean
Visual Basic (Verwendung)
Dim instance As String
Dim value As String
Dim returnValue As Boolean

returnValue = instance.Contains(value)
C#
public bool Contains (
    string value
)
C++
public:
bool Contains (
    String^ value
)
J#
public boolean Contains (
    String value
)
JScript
public function Contains (
    value : String
) : boolean

Parameter

value

Das zu suchende String-Objekt.

Rückgabewert

true, wenn der value-Parameter in dieser Zeichenfolge vorkommt oder value eine leere Zeichenfolge ("") ist, andernfalls false.
AusnahmetypBedingung

ArgumentNullException

value ist NULL (Nothing in Visual Basic).

Diese Methode führt eine Wortsuche (unter Berücksichtigung von Groß- und Kleinschreibung und der Kultur) unter Verwendung der aktuellen Kultur durch. Die Suche beginnt an der Position des ersten Zeichens dieser Zeichenfolge und endet an der Position des letzten Zeichens.

Im folgenden Codebeispiel wird bestimmt, ob die Zeichenfolge "fox" eine Teilzeichenfolge in einem berühmten Zitat ist.

Visual Basic
' This example demonstrates the String.Contains() method
Imports System

Class Sample
   Public Shared Sub Main()
      Dim s1 As String = "The quick brown fox jumps over the lazy dog"
      Dim s2 As String = "fox"
      Dim b As Boolean
      b = s1.Contains(s2)
      Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'Is the string, s2, in the string, s1?: True
'
C#
// This example demonstrates the String.Contains() method
using System;

class Sample 
{
    public static void Main() 
    {
    string s1 = "The quick brown fox jumps over the lazy dog";
    string s2 = "fox";
    bool b;
    b = s1.Contains(s2);
    Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);
    }
}
/*
This example produces the following results:

Is the string, s2, in the string, s1?: True
*/
C++
// This example demonstrates the String.Contains() method
using namespace System;
int main()
{
   String^ s1 = "The quick brown fox jumps over the lazy dog";
   String^ s2 = "fox";
   bool b;
   b = s1->Contains( s2 );
   Console::WriteLine( "Is the string, s2, in the string, s1?: {0}", b );
}

/*
This example produces the following results:

Is the string, s2, in the string, s1?: True
*/
J#
// This example demonstrates the String.Contains() method
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        String s1 = "The quick brown fox jumps over the lazy dog";
        String s2 = "fox";
        boolean b;
        b = s1.Contains(s2);
        Console.WriteLine("Is the string, s2, in the string, s1?: {0}", 
            (System.Boolean)b);
    } //main
} //Sample
/*
This example produces the following results:

Is the string, s2, in the string, s1?: True
*/

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

.NET Framework

Unterstützt in: 2.0
© 2012 Microsoft. Alle Rechte vorbehalten. Nutzungsbedingungen | Markenzeichen | Informationen zur Datensicherheit
Page view tracker