Hi!
I want to read a text file word by word to string and display it in a text box. Given below is my piece of code. If I give the input string as "this is my cat", this piece of code only displays 'cat'. whatever input i give, program on compilation shows only last word. What's wrong in it. Please help.
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
string file = openFileDialog1.FileName;
try
{
// display the input file in textbox1
string text1 = File.ReadAllText(file);
textBox1.Text = text1;
//read the text file again
string s = File.ReadAllText(file);
string[] words = s.Split(' ');
foreach (string word in words)
{
// show the resulting string in textbox2
textBox2.Text=word;
}
}