How to count words in array that start with a capital letter in C#

1 Answer

0 votes
using System;
using System.Linq;
using System.Text.RegularExpressions;
 
class Program
{
    public static void Main()
    {
        string[] arr = {"C#", "c", "c++", "Python", "PHP", "swift"};
       
        var totalCapitalLetter = arr.Count(s => {return Regex.IsMatch(s, "^[A-Z]");});
    
        Console.WriteLine(totalCapitalLetter);
    }
}
 
 
 
 
/*
run:
 
3
 
*/

 



answered Nov 1, 2020 by avibootz
...