8.17 - 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.


Solution

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();
    }
}


Popular Posts