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)

Syntax
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)
public bool Contains (
string value
)
public:
bool Contains (
String^ value
)
public boolean Contains (
String value
)
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.

Ausnahmen

Hinweise
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.

Beispiel
Im folgenden Codebeispiel wird bestimmt, ob die Zeichenfolge "fox" eine Teilzeichenfolge in einem berühmten Zitat ist.
' 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
'
// 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
*/
// 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
*/
// 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
*/

Plattformen
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.

Versionsinformationen
.NET Framework
Unterstützt in: 2.0

Siehe auch