Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

how to retrieve/print a column from string array in C#

Status
Not open for further replies.

siemprepeligroso

Newbie level 6
Joined
Aug 4, 2009
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,387
Dear friends,
I was trying to do some task in C# but now I am stuck
first I should read some data from a text file and arrange them i form of a rows
later I just needed to show the content of row number 5
after this I had to find the average of column 4 (by converting data from string to integer)
and in the end print out the column 4

I did manage to do first 3 task but I am not able to print our the 4th column


here is my code:

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

namespace HW0_DM
{
class ReadFile
{
static void Main(string[] args)
{

// Read the file lines into a string array.


string[] row = System.IO.File.ReadAllLines(@"C:\testfile.txt");

System.Console.WriteLine("Contents of testfile.txt =:");
System.Console.WriteLine("\n\tName\tSurname\tPOS\tAge\n");



foreach (string line in row)
{
Console.WriteLine("\t" + line);
}

Console.WriteLine("\nResult of row 5\n\n\t" + row[4]);



var ages =
from column in row
let a = column.Split('\t')
select Convert.ToInt32(a[3]);
var results = ages.ToArray();


//average of 4th column
double avgage = results.Average();

Console.WriteLine("\nResult of column 4\n\n\t");
Console.Write(results);



Console.Write("\n\nAverage Team Age:\t");

Console.Write(avgage + "\n");




// Keep the console window open in debug mode.
Console.WriteLine("\nPress any key to exit.");
System.Console.ReadKey();
}
}
}


HOW CAN I PRINT TO THE USER CONSOLE THE CONTENT OF COLUMN 4

here is the content of the text file:

Theo Walcott FWD 22
Tomas Rosicky CMF 24
Bacary Sagna LB 27
Gael Clichy RB 26
Abou Diaby CMF 21
Kolo Toure CB 26
Reply With Quote
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top