We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Monday, January 25, 2016

Find the number of All Capital Letters from a given string in C#

  class CheckCapitalChar
    {
        public static string CountCapital(string str)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < str.Length - 1; i++)
            {

                char ch = str[i];
                if (char.IsUpper(ch))
                {
                    sb.Append(ch);
                }
            }
            return sb.ToString();

        }
        public static void Main()
        {
            Console.WriteLine("Enter the string");
            string str = Console.ReadLine();
            string result = CountCapital(str);
            Console.WriteLine(result);
            Console.ReadLine();
        }


    }
Output:


No comments: