Ejercicio
Convertir cualquier archivo a mayúsculas
Objetivo
Escribe un programa para leer un archivo (de cualquier tipo) y volcar su contenido a otro archivo, cambiando las letras minúsculas a mayúsculas.
Debe entregar solo el archivo ".cs", con su nombre en un comentario.
Código de Ejemplo
// 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
}
}