Convert any file to uppercase Learn programming C#

Lesson:

File Management


Exercise:

Convert any file to uppercase


Objetive:

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.


Code:

using System;
using System.IO;
public class binaryFileToUpper
{

    public static void Main()
    {
        BinaryReader inFile = new BinaryReader(
            File.Open("example.exe", FileMode.Open));

        BinaryWriter outFile = new BinaryWriter(
            File.Open("example.exe.upper", FileMode.Create));

        long filesize = inFile.BaseStream.Length;

        for (long i = 0; i < filesize; i++)
        {
            byte b = inFile.ReadByte();
            if ((b >= Convert.ToByte('a')) &&
              (b <= Convert.ToByte('z')))
                b -= 32;
            outFile.Write(b);
        }
        inFile.Close();
        outFile.Close();
    }
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.