String Contains() Method in C#



String Contains() Method in C#

Contains() – The C# Contains method checks whether specified character or string is present inside a given string or not.

The string contains method returns bool value true/false, if string found in content of specified string then returns true other wise returns false.


C# Example for String Contains()

Here, we have two string str1 and str2, we check if the str2 value found in str1 the the result will be true, if str2 content is not found in str1 the result will be false.

meeraacademy.com
String Contains Example in C#

In above example, the first time to find out if the string2 value “meera” is present in the string1 “meera”. The string was present, it returned result “True”. Then second time to find out if the string2 value “meera academy” is present in the string1 “meera”. The string was not found, it returned result “False”.

C# code for Button Click :

protected void Button1_Click(object sender, EventArgs e)
{
string str1=TextBox1.Text;
string str2 =TextBox2.Text;
Label1.Text = str1.Contains(str2).ToString();
}

Subscribe us

If you liked this c#.net post, then please subscribe to our YouTube Channel for more c#.net video tutorials.

We hope that this C#.net tutorial helped you to understand String Contains() Property.


Next asp.net tutorial we will learn about String Equals() Function.