Check existence of one string in another string in C#
If we want to check whether a string contains a specific string or character we can use .Contains method.
We can also use IndexOf method to check existence of a string in another string.
string str1 = "Orange";
if (str1.Contains("an"))
{
Console.WriteLine("str1 contains an");
}
Using IndexOf method
if (str1.IndexOf("an") > -1)
{
Console.WriteLine("str1 contains an");
}
Comments
Post a Comment