String contains character
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 |
class Program { static void Main(string[] args) { //this section create a string variable. string stringVal = "abcde fghi jklmn"; Console.WriteLine("string.................."); Console.WriteLine(stringVal); //this line check string contains character 'b' or not. Boolean resultb = stringVal.Contains('b'); //this line check string exists character 'z' or not. Boolean resultz = stringVal.Contains('z'); Console.WriteLine("\nstring contains character ('b')?........."); Console.WriteLine(resultb); Console.WriteLine("\nstring contains character ('z')?..........."); Console.WriteLine(resultz); Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 10 |
string.................. abcde fghi jklmn string contains character ('b')?......... True string contains character ('z')?........... False |