Sunday, October 31, 2021

Uppercase Consonants in C#

 A simple program that will ask the user to give a string and then the program will uppercase the consonants in a given string using C# programming language.

  I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Program Listing

Program.cs

using System;


public class Program

{

  public static void Main()

  {

    Console.Write("\n");

    Console.Write("\tUppercase Consonants in C#");

    Console.Write("\n\n");

    Console.Write("\tEnter a string: ");

    string input = Console.ReadLine();


    Console.Write("\n\n");

    Console.Write("\tGiven String : " + input);

    Console.Write("\n\n");

    Console.Write("\tThe Result: ");

    foreach (char ch in input)

    {

      PrintChar(ch);

    }


    Console.Write("\n\n");

    Console.Write("\tEnd of Program");

    Console.Write("\n");

    Console.ReadKey();

  }

     

  public static void PrintChar(char ch)

  {

    ConsoleColor old_color = Console.ForegroundColor;


    if (ch.IsConsonant())

    {


      Console.ForegroundColor = ConsoleColor.Yellow;

      Console.Write(Char.ToUpper(ch));

      Console.ForegroundColor = old_color;

    }

    else

      Console.Write(ch);

  }

}



Characterextensions.cs

using System; public static class CharacterExtensions { public static bool IsConsonant(this char ch) { const string consonants = "BCDFGHJKLMNPQRSTVWXYZ"; return consonants.IndexOf(Char.ToUpper(ch)) != -1; } }


No comments:

Post a Comment