String.Contains (Método)
.NET Framework 3.5
Actualización: noviembre 2007
Devuelve un valor que indica si el objeto String especificado aparece dentro de esta cadena.
Ensamblado: mscorlib (en mscorlib.dll)
public boolean Contains( String value )
public function Contains( value : String ) : boolean
Parámetros
- value
- Tipo: System.String
Objeto String que se va a buscar.
Valor devuelto
Tipo: System.BooleanEs true si el parámetro value aparece en esta cadena o si value es la cadena vacía (""); de lo contrario, es false.
| Excepción | Condición |
|---|---|
| ArgumentNullException | El valor de value es null. |
En el ejemplo de código siguiente se determina si la cadena "fox" es una subcadena de una cita conocida.
// 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
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 Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile para Smartphone, Windows Mobile para Pocket PC, Xbox 360
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.