Programming Course in C# ¡Free!

Convert a text file to uppercase

 Saturday, April 06, 2013 published by Exercises C#
Proposed exercise

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.

Output



Solution


using System;
using System.IO;

class FileLowerCaseToUpperCase
{
static void Main()
{
Console.Write("Enter name file: ");
string name = Console.ReadLine();

if (File.Exists(name))
{
StreamReader fileRw = File.OpenText(name);
StreamWriter fileWr = File.CreateText(name + ".dat");
string line;
do
{
line = fileRw.ReadLine();
if (line != null)
fileWr.WriteLine(line.ToUpper());
}
while (line != null);
fileRw.Close();
fileWr.Close();
}
}
}