How to read an array of values, select the specified [row, column] from the file being read, and wri

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All,<br/>
<br/>
I have a text file of integer values (301 rows by 301 columns) in an array (values separated by single-spaces), and I am trying to read the file using
File.ReadAllLines() to then get a specified value at one location (identified by its [row, column]) and write it to the Console window. How can I do this correctly?<br/>
<br/>
Here is a snippet of my code:
static void Main(string[] args) <br/>
{ <br/>
int ncols = 301; <br/>
int nrows = 301; <br/>
int col_index = 0; <br/>
int row_index =0;
for (col_index = 0; col_index < ncols; col_index++) <br/>
{ <br/>
for (row_index = 0; row_index < nrows; row_index++) <br/>
{ <br/>
string[] lines = File.ReadAllLines("Filename"); <br/>
string[][] data = lines.Select(line => line.Split( ).ToArray()).ToArray(); <br/>
string cell = data[2][2];
Console.WriteLine("Value at cell [2,2] =", cell); <br/>
Console.ReadLine(); <br/>
} <br/>
row_index++; <br/>
}
<br/>
<br/>
Im especially new to C# (and all programming really), and Im attempting to denote the array values by their respective [row #, column #] using indexers. I probably dont need to use the
for loop for this, but Im unsure. Overall, I dont know if this is an inappropriate approach or not.<br/>
<br/>
Any assistance would be appreciated. Thank you in advance.<br/>
<br/>
-AD-
<br/>
<br/>
<br/>
<hr class="sig AndrewDen

View the full article
 
Back
Top