Monday 24 December 2012

Convert Perl Script to C#


Convert Perl Script to C#


Make Use of the following function to convert your Perl Script to C#:


public void PerlTransFile(string filename)

{

string outDelim = ",";

char fs = '|';

Hashtable neigh = new Hashtable();

using (StreamReader sr = new StreamReader("TestFile.txt"))

{

string line;

while ((line = sr.ReadLine()) != null)

{

string[] temp = line.Split(fs);

neigh[string.Format("{1}{0}{2}{0}{3}", fs.ToString(), temp[1], temp[2], temp[3])] =

string.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}{6}",

fs.ToString(), temp[34], temp[14], temp[15], temp[32], temp[33], temp[24]);

}

foreach(string key in neigh.Keys)

{

string[] a = neigh[key].ToString().Split(',');

for(i = 0 ; i < a.Length; i++)

Console.WriteLine("{1}{0}{2}{0}{3}{0}", fs, key, i, a[ i ]);

}

}

2 comments:

  1. If i use this i get an IndexOutOfRangeException everytime i use it on the first line of my Perl Script.

    ReplyDelete
  2. Can you post the Code? Are you keeping the Perl script in a flat file??

    ReplyDelete

Thank You for Your Comments. We will get back to you soon.

back to top