Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Sir
I am uday,

I am developing application c sharp win form. and I want to read textFile.

and store in string array format.
please give solution.

How to read text file and store it into string array.and my text file contains arount 20000 rows.
Posted
Comments
Pravin Patil, Mumbai 24-Aug-11 7:25am    
First of all let me tell you that it is not a good option to store a whole 20,000 line file in an array.
Array refers to e.g array[10]
Do you want to store first line at array[0], second line at array[1] etc....?

 
Share this answer
 
Comments
udusat13 24-Aug-11 7:24am    
thanks sir.
please tell me in details and i want count also
Rob Philpott 24-Aug-11 7:26am    
Very nice solution, much better than mine below. You see, you learn something new everyday.
Prerak Patel 24-Aug-11 7:33am    
There is sample code in link itself. Did you check the link?
Simon Bang Terkildsen 24-Aug-11 8:41am    
Nice and simply +5
Use a StreamReader to read the file a line at a time, then add each row to a List<string>. Then use .ToArray() on that.
 
Share this answer
 
v3
Comments
udusat13 24-Aug-11 7:27am    
please sir give me example
first make one button and textbox and try this code.

private void button1_Click(object sender, EventArgs e)
{

string fpath="E:\\one.txt";
StreamReader dr = new StreamReader(fpath);
string[] arr=new string[1000];
int i = 0;
string st = "";
while (dr.Peek() !=-1)
{
arr[i] = dr.ReadLine();
st = st + arr[i].ToString()+"\n";
i++;
}
textBox1.Text = st;
}

here i declared string array and that size is 1000, and get value from reader.

i hope this is useful to you;
take care bye bye
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900