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

Popular posts from this blog

Using Progress Bar In C#

Get elements by class name in javascript

Jquery serer side datatables in asp.net