The Contains() Method is used to find a substring from the String.
public class MyApplication { public static void Main(string[] args) { string x = "Beautiful"; bool y = x.Contains("tif"); if (y == true) { System.Console.WriteLine("The substring tif is present in the String"); } else { System.Console.WriteLine("The substring tif is not present in the String"); } } }
In the above code, we have declared a String Beautiful and assigned it to a variable x.
string x = "Beautiful";
And we would be searching the substring tif, from the String, Beautiful.
So, we have used the Contains() Method to find if the substring tif is present in the String, Beautiful.
bool y = x.Contains("tif");
And what Contains() Method does is, goes to the String Beautiful and searches if the substring tif is present in it or not.
And finds the substring substring tif is present.
And the below output is printed.