Programming Course in C# ¡Free!

Convert any file to uppercase

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

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.

Output



Solution


using System;
using System.IO;

public class ConverAnyFile
{
public static void Main()
{
BinaryReader fileR = new BinaryReader(
File.Open("data.data", FileMode.Open));

BinaryWriter fileW = new BinaryWriter(
File.Open("data.data.txt", FileMode.Create));


int size = fileR.BaseStream.Length;
for (int i = 0; i < size; i++)
{
byte b = fileR.ReadByte();

if (b >= Convert.ToByte('a') && b <= Convert.ToByte('z'))
b -= 32;  

fileW.Write(b);
}
fileR.Close();
fileW.Close();
}
}