How to Count Only Letters in a String in C#

This is very interesting and logic building program in C# for beginners. The program will count only letters in a given strings e.g. a1B2C456 has only 3 Letters.

Source Code 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace assad
{
class countLetters
{
static void Main(string[] args)
{
welcomeScrean();
String str = "A1B2C36gfhf5";
int numberOfLetters = 0;
foreach (char letter in str)
{
if (Char.IsLetter(letter))
numberOfLetters++;
}
Console.WriteLine("\tStriing " + str + " has " + numberOfLetters + " letters.");
int ab = Console.Read();
}
private static void welcomeScrean()
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.Write("\t*******************************************************" + "\n"
+ "\t*******************************************************" + "\n"
+ "\t** Welcome To **" + "\n"
+ "\t** Count Letters **" + "\n"
+ "\t** Program **" + "\n"
+ "\t*******************************************************" + "\n"
+ "\t*******************************************************\n\n\n\n");
}
}
}

Output of the Program

Count Only Letters in a String in C#

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment