Hi,
I am new to c# and I am trying to read a file which is of format:
1 2 3
3 4 5
6 7 8
1 2
3 4
the problem is I am not able to read file in given format, I am not able to tell the streamReader to read separately. Like for example if I ask to read till end of file I can't seperate the format altogether. I have to store first format in different arrays and the other format into different arrays for example:
arrayList A will store 1,3,6
arrayList B will store 2,4,7
arrayList C will store 3,5,8
and 2 other arrays will store
arrayList D will store 1,3
arrayList f will store 2,4
I tried to search it but I didn't got any success till now.
some code that I tried was:
StreamReader myFile = new StreamReader(fileInputTextBox.Text);
//Reads the file line by line
while (!myFile.EndOfStream)
{
string myString = myFile.ReadLine(); //reads file line by line
fillArray(myString);
}
myFile.Close();
This is the code I am using to read file, since I don't know how to make the streamReader read till my format change I am just reading till end of stream.
another method that I use to store it into an array:
public void formArray(string fileString)
{
string filestring=fileString;
string[] tokens = new string[3];
tokens =filestring.Split(' '); //split string with delimiter as space
A.Add(tokens[0]);
B.Add(tokens[1]);
C.Add(tokens[2]);
//don't know how to work for D and F
}
I am really confused can anyone suggest how can I do that.
Thanks!!