Basic Programming C# Examples

C# Program to Remove All Non-letters from a given string

The Program in C# Program to Remove All Non-letters from a given string is given below:

using System;

namespace RemoveNonLetters
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family,enter a string here to remove all non-letters characters: ");
            string input = Console.ReadLine();

            string output = "";

            foreach (char c in input)
            {
                if (char.IsLetter(c))
                {
                    output += c;
                }
            }

            Console.WriteLine("Okay, the result: " + output);
        }
    }
}

Output:

Hello Codeauri Family,enter a string here to remove all non-letters characters: Codeauri makes programming e@sy
Okay, the result: Codeaurimakesprogrammingesy

Pro-Tips💡

Here are the step by step execution of above program:

  1. using System;: This line includes the System namespace, which provides access to various classes and methods, including the Console class used in this program.
  2. namespace RemoveNonLetters: This line declares a namespace called RemoveNonLetters that the code resides in. A namespace helps organize and categorize code.
  3. class Program: This line declares a class named Program that contains the code to be executed.
  4. static void Main(string[] args): This line declares the Main method, which is the entry point of the program. The static keyword indicates that the method belongs to the class, not to an instance of the class. The void keyword means that the method does not return a value. The string[] args parameter is used to receive command line arguments, but it is not used in this program.
  5. Console.WriteLine("Hello Codeauri Family,enter a string here to remove all non-letters characters: ");: This line displays a prompt to the user, asking them to enter a string.
  6. string input = Console.ReadLine();: This line reads the string entered by the user and stores it in a variable called input.
  7. string output = "";: This line declares and initializes an empty string variable called output, which will be used to store the result.
  8. foreach (char c in input): This line starts a foreach loop that iterates through each character in the input string. The variable c represents the current character in each iteration of the loop.
  9. if (char.IsLetter(c)): This line checks if the current character c is a letter using the char.IsLetter method.
  10. output += c;: If the character is a letter, it is added to the output string.
  11. Console.WriteLine("Okay, the result: " + output);: This line displays the final result, which is the output string with all non-letter characters removed.
  12. The program ends when the Main method finishes executing.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X