B
Bob Cummings
Greetings
I am stumped. I am trying to create some initial conditions object by
reading from a file. These objects have an integer ID and then a
list of sub objects. The problem is I will not know at run time how
many sub objects there may be. Here is an example of the input text file.
0
abiebals,20,50,78
acerrubr,100
betualle,100,125,180
//sand old growth
2
abiebals,100
betualle,100,125,180
What I would like to do is read the file line by line and split it into
a fields string array. Then if the size of my fields array is equal to
1 I will know it is time to build a new object. I would then like to
reset the stream object back to the position it had before it read the
integer and pass it back to the Controller class to begin the building
of another initial conditions object. But this does not seem to work.
Any suggestions ??
Here is what I have tried.
string [] fields;
string line = inFile.readLine();
fields = line.Split(',');
while (fields.Length>1)
{
long position;
InitialSpecies IS = new InitialSpecies();
IS.build(fields);
mySpecies.Add(IS);
position = inFile.position;
line = inFile.readLine();
if (line != null)
{
fields = line.Split(',');
if(fields.Length ==1)// reset the stream position
{
inFile.position = position; }
}// end if end of file
}
I am stumped. I am trying to create some initial conditions object by
reading from a file. These objects have an integer ID and then a
list of sub objects. The problem is I will not know at run time how
many sub objects there may be. Here is an example of the input text file.
0
abiebals,20,50,78
acerrubr,100
betualle,100,125,180
//sand old growth
2
abiebals,100
betualle,100,125,180
What I would like to do is read the file line by line and split it into
a fields string array. Then if the size of my fields array is equal to
1 I will know it is time to build a new object. I would then like to
reset the stream object back to the position it had before it read the
integer and pass it back to the Controller class to begin the building
of another initial conditions object. But this does not seem to work.
Any suggestions ??
Here is what I have tried.
string [] fields;
string line = inFile.readLine();
fields = line.Split(',');
while (fields.Length>1)
{
long position;
InitialSpecies IS = new InitialSpecies();
IS.build(fields);
mySpecies.Add(IS);
position = inFile.position;
line = inFile.readLine();
if (line != null)
{
fields = line.Split(',');
if(fields.Length ==1)// reset the stream position
{
inFile.position = position; }
}// end if end of file
}