Reading from a text file
Hi I have a problem in reading from a text file line by line.
I will have this type of text file:
00001110000, 000
00110101010, 001
00000101010, 111
and I want to read the text file line by line - store the part before the ',' in an array and the part after the ',' in another array!
Any help please?!
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Nilanka DharmadasaRank #1,875 · 794 reputationPosted Nov 24, 2009, 3:18 AM EST
As I understod your problem, this code will be the answer for your problem.
private void button1_Click_1(object sender, EventArgs e) { System.IO.StreamReader re = System.IO.File.OpenText("C:\\myfile.txt"); string input = null; string[] wordarray = new string[2]; char[] array1; char[] array2; while ((input = re.ReadLine()) != null) { if (string.IsNullOrEmpty(input)) continue; wordarray[0] = input.Substring(0,input.IndexOf(","));//The part before the ','. wordarray[1] = input.Substring(input.IndexOf(",") + 1);////The part after the ','. if (!string.IsNullOrEmpty(wordarray[0])) array1 = wordarray[0].ToCharArray(); if (!string.IsNullOrEmpty(wordarray[1])) array2 = wordarray[1].ToCharArray(); } re.Close(); }If this is not what you want, please let me know. I will help you.
If you find this useful, please do not forget to mark 'Do you like this answer' check box.