Convert Any File To Uppercase - C# Programming Exercise

This C# exercise involves creating a program that reads a file of any kind and dumps its content into another file, applying a transformation in the process. The transformation to be made is to change all lowercase letters to their uppercase equivalents. This exercise is perfect for learning how to work with different types of files and perform text manipulations in C#.

The program should be able to read any type of file, interpret its content, and iterate through it, detecting lowercase letters and replacing them with their uppercase versions. The result must then be saved into a new file. This exercise is great for learning to handle input and output in C#, as well as working with strings and applying transformations to them.

Additionally, the program must include a comment with your name in the .cs file submitted, ensuring the code is authored by you. This exercise helps improve programming skills in C#, specifically in file handling and text manipulation.

 Category

File Management

 Exercise

Convert Any File To Uppercase

 Objective

Write a program to read a file (of any kind) and dump its content to another file, changing the lowercase letters to uppercase.

You must deliver only the ".cs" file, with you name in a comment.

 Write Your C# Exercise

// Importing the System namespace for basic functionalities like Console I/O
using System;

// Importing the System.IO namespace to handle file operations like reading and writing files
using System.IO;

class ConvertToUppercaseFile  // Define the class ConvertToUppercaseFile
{
    // Method to read a file, convert its content to uppercase, and save it to a new file
    public static void ConvertFileToUppercase(string inputFileName, string outputFileName)
    {
        string fileContent = File.ReadAllText(inputFileName);  // Reading the content of the input file
        string uppercasedContent = fileContent.ToUpper();  // Converting the file content to uppercase
        File.WriteAllText(outputFileName, uppercasedContent);  // Writing the uppercase content to the output file
        Console.WriteLine($"File content has been converted to uppercase and saved to {outputFileName}");  // Printing a confirmation message
    }

    // Main method - entry point of the program
    static void Main(string[] args)
    {
        Console.Write("Enter the input file name (with extension): ");  // Asking the user for the input file name
        string inputFileName = Console.ReadLine();  // Reading the input file name entered by the user
        string outputFileName = Path.GetFileNameWithoutExtension(inputFileName) + "_uppercase" + Path.GetExtension(inputFileName);  // Creating the output file name with "_uppercase" suffix
        ConvertToUppercaseFile.ConvertFileToUppercase(inputFileName, outputFileName);  // Calling the method to convert the file content to uppercase
    }
}

 Share this C# exercise

 More C# Programming Exercises of File Management

Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.

  •  File inverter

    This C# exercise involves creating a program to "invert" a file. The program must take an original file and create a new one with the same name but with the ".inv" ex...

  •  File encrypter

    This C# exercise involves creating a program to encrypt a text file into another text file. The program should be able to read the content of a text file, apply an en...

  •  Count words

    This C# exercise involves creating a program to count the number of words stored in a text file. The program should read the content of a text file, process it, and c...

  •  BMP width and height, BinaryReader

    This C# exercise involves creating a program to display the width and height of a BMP file using a BinaryReader. The program should read the BMP file header an...

  •  TXT to HTML translator

    This C# exercise involves creating a "Text to HTML converter". The program should read a source text file and create an HTML file from its contents. The destination f...

  •  Invert binary file V2

    This C# exercise involves creating a program to "invert" a file using a FileStream. The program should create a file with the same name as the original file, b...