String contains multiple values
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
class Program { static void Main(string[] args) { //this section create a string variable. string stringValue = "red green blue indianred brown"; //this section create array of string. string[] multipleRed = new string[] { "red", "indianred" }; //here we create an array of multiple string which we want to check in string string[] multipleBlue = new string[] { "blue", "darkblue" }; Console.WriteLine("string.................."); Console.WriteLine(stringValue); Console.WriteLine("multiple string (red colors) to check.................."); foreach (string s in multipleRed) { Console.WriteLine(s); } Boolean resultRed = multipleRed.All(x => stringValue.Contains(x)); Console.WriteLine("string contains multiple values(red)?..........."); Console.WriteLine(resultRed); Console.WriteLine("multiple string (blue colors) to check.................."); foreach (string s in multipleBlue) { Console.WriteLine(s) ; } Boolean resultBlue = multipleBlue.All(x => stringValue.Contains(x)); Console.WriteLine("string contains multiple values(blue)?..........."); Console.WriteLine(resultBlue); Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
string.................. red green blue indianred brown multiple string (red colors) to check.................. red indianred string contains multiple values(red)?........... True multiple string (blue colors) to check.................. blue darkblue string contains multiple values(blue)?........... False |