Using C# to check if string contains a string in string array

To check any string value in a string array in C#, please follow below code..

Please find below C# source code, that shows how to search particular string value in the array..

 string stringToSearch = "sagar";
 string[] stringArrayValues = { "himasagar", "kutikuppala", "sagar", "madhu", "ravi" };
 foreach (string val in stringArrayValues)
 {
     if (stringToSearch.Contains(val))
     {
         // Further steps...
     }
 }

To check the search string, that matched in any one of the value in string array, use below C# code:

 string stringToSearch = "sagar";
 string[] stringArrayValues = { "himasagar", "kutikuppala", "sagar", "madhu", "ravi" };
       
 if (stringArrayValues.Any(stringToSearch.Contains))
 {
    // Further steps...
 }

To check the search string , that contains in all the values in string array, use below C# code:

 string stringToSearch = "sagar";
 string[] stringArrayValues = { "himasagar", "kutikuppala", "sagar", "madhu", "ravi" };
        
 if (stringArrayValues.All(stringToSearch.Contains))
 {
    // Further steps...
 }


What is GST

GST (Goods and Service Tax) is a comprehensive tax on the supply of goods and services at each stage of any transaction. Read More

Income Tax Information

An income tax is a tax imposed by government on income earned by you. Income tax is a key source of funds that the government uses to fund its activities and serve the public. Read More

General Insurance Companies in India

General insurance is insurance for valuables other than our life and health. General insurance covers the insurer against damage, loss and theft of your valuables. Read More



Types of Bank Loans In India

Loan means lending money from one individual or entity to another. A loan has three components – principal or the borrowed amount, rate of interest and tenure or duration for which the loan is availed. Read More

List of Banks in India

The Reserve Bank of India is the central Bank that is fully owned by the Government of India. It is governed by a central board (headed by a Governor) appointed by the Central Government. Read More

List of Educational Institutions in India

The following list of comprehensive websites on higher education in India. These websites will provide detailed information on education system in India. Read More