C# String Contains
Description
String Contains
returns a value indicating whether a
specified substring occurs within this string.
Syntax
String.Contains
has the following syntax.
public bool Contains(
string value
)
Parameters
String.Contains
has the following parameters.
value
- The string to seek.
Returns
String.Contains
method returns true if the value parameter occurs within this string, or if value is the empty
string (""); otherwise, false.
Example
The following example determines whether the string "fox" is a substring of a familiar quotation.
//from w w w. ja va2 s . c om
// 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);
}
}
The code above generates the following result.