String Contains Example

 In this Asp .Net Tutorial we will learn who to use String.Contains method. String.Contains method is used to check whether a substring/text occurs within string or not.  This method uses case sensitive and culture-insensitive comparison to check substring with in a string. This method returns true if the substring is present in the string and returns false if the substring is not present in the string. 
 

This method is very usefull when you want to check wether the substring/text is present within the string or not. If you want to compare two strings you can use String.CompareTo method.

 

HTML Source

 

 

  
Actual String
Result

 

 

Code Behind

 

 

 protected void btnCheckValue_Click(object sender, EventArgs e)
    {
        string s1 = lblString.Text;
        bool result = s1.Contains(txtStringToCheck.Text.Trim());
        lblResult.Text = result.ToString();
    }

 

 

Final Output

String Contains Example in Asp .Net

In th above example you can see if I search substring with the same case then String.Contains method returns true and if I search substring with uppercase it returns false. This is because String.Contains Method is case sensitive.

 
We are nothing without our users ! You can help us offer even more high quality content. Please share our page !
Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
6 + 6 =
 
About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2019 CodingFusion
75 Important SQL Server queries you should know