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 148 views
1 answer 196 views
1 answer 118 views
2 answers 148 views
1 answer 148 views
148 views asked Mar 10, 2017 by avibootz
4 answers 334 views
334 views asked Mar 15, 2015 by avibootz
...