Q:

Write a C# Sharp program to get the number of letters and digits in a given string

0

Write a C# Sharp program to get the number of letters and digits in a given string

Sample Output:

Original string:: Python 3.0
Number of letters: 6  Number of digits: 2

Original string:: dsfkaso230samdm2423sa
Number of letters: 14  Number of digits: 7

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            string text;
            text = "Python 3.0";
            Console.WriteLine("Original string:: "+text);
            Console.WriteLine(test(text));
            text = "dsfkaso230samdm2423sa";
            Console.WriteLine("\nOriginal string:: " + text);
            Console.WriteLine(test(text));
        }
        public static string test(string text)
        {
            int ctr_letters = text.Count(char.IsLetter);
            int ctr_digits = text.Count(char.IsDigit);            
            return "Number of letters: " + ctr_letters + "  Number of digits: " + ctr_digits;
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now