How to check if a specific character exists in a string with C#

2 Answers

0 votes
using System;

class Program
{
    static void Main() {
        String s = "c# programming"; 
       
        if (s.IndexOf('p', StringComparison.CurrentCultureIgnoreCase) != -1) 
            Console.Write("yes");            
        else
            Console.Write("no");
    }
}




/*
run:

yes

*/

 



answered Jan 10, 2020 by avibootz
0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        String s = "c# programming"; 
       
        if (s.ToLower().Contains('p')) 
            Console.Write("yes");            
        else
            Console.Write("no");
    }
}




/*
run:

yes

*/

 



answered Jan 10, 2020 by avibootz

Related questions

2 answers 113 views
1 answer 142 views
1 answer 148 views
1 answer 79 views
2 answers 106 views
1 answer 119 views
119 views asked Mar 10, 2017 by avibootz
...