Transpose of a text file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"C:\Users\saikatd\";
            string[] lines = File.ReadAllLines(path + "input.txt");
            int maxLength = lines.Max(x => x.Length);
            char[,] ch1 = new char[maxLength, lines.GetLength(0)];
            int col = 0;
            foreach (string line in lines)
            {
                for (int i = 0, row = 0; i < line.Length; i++, row++)
                {
                    ch1[row, col] = line[i];
                }
                col++;
            }
            StreamWriter sw = new StreamWriter(path + "output.txt", false);
            for (int i = 0; i < ch1.GetLength(0); i++)
            {
                for (int j = 0; j < ch1.GetLength(1); j++)
                {
                    sw.Write(ch1[i, j]);
                }
                sw.WriteLine();
            }
            sw.Close();
        }
    }
}

input.txt
==========
Begin on Old Madras Road
Left on Domlur Flyover
Left on 100 Feet Road
Right on Sarjapur Road
Right on Hosur Road
Right on Ganapathi Temple Road

output.txt
===========
BLLRRR
eeeiii
gffggg
itthhh
n  ttt
 oo   
onnooo
n  nnn
 D1   
Oo0SHG
lm0aoa
dl rsn
 uFjua
Mrearp
a ep a
dFtuRt
rl roh
ayR ai
sooRd 
 vao T
Reda e
or d m
a    p
d    l
     e
      
     R
     o
     a
     d
Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s