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...
}