Exercise
Convert A Text File To Uppercase
Objective
Write a program to read a text file 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
C# Exercise Example
// Importing the System namespace to access basic operations like Console and File handling
using System;
// Importing the System.IO namespace to handle file operations
using System.IO;
// Defining the ConvertToUppercase class
class ConvertToUppercase
{
// Method to convert the content of a text file to uppercase
public static void ConvertFileToUppercase(string inputFileName, string outputFileName)
{
// Reading the content of the input file using File.ReadAllText
string fileContent = File.ReadAllText(inputFileName);
// Converting the content to uppercase using the ToUpper method
string uppercasedContent = fileContent.ToUpper();
// Writing the converted content to the output file using File.WriteAllText
File.WriteAllText(outputFileName, uppercasedContent);
// Displaying a message to the user that the file has been successfully written
Console.WriteLine($"File content has been converted to uppercase and saved to {outputFileName}");
}
// Main method where execution starts
static void Main(string[] args)
{
// Asking the user to input the file name for reading
Console.Write("Enter the input file name (with extension): ");
// Reading the file name from the user input
string inputFileName = Console.ReadLine();
// Creating the output file name by appending "_uppercase" to the original file name
string outputFileName = Path.GetFileNameWithoutExtension(inputFileName) + "_uppercase" + Path.GetExtension(inputFileName);
// Calling the method to convert the content of the input file to uppercase and save it to the output file
ConvertFileToUppercase.ConvertFileToUppercase(inputFileName, outputFileName);
}
}