L
L
libera2015-12-14 20:40:34
C++ / C#
libera, 2015-12-14 20:40:34

Reading from openfiledialog file and outputting to 2 textboxes?

DialogResult result = openFileDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    string file = openFileDialog1.FileName;
                    try
                    {
                        string text = File.ReadAllText(file);
                        textBox1.Text = (text);
                    }
                    catch (IOException exception)
                    {
                        MessageBox.Show(exception.Message);
                    }
                }

Everything normally displays, only in textBox1, but I need it in textBox2.
At the same time, the file has a division ' : ' and it should enter 1 part in textBox1, and what after ' : ' in textBox2 Line by
line.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kovalsky, 2015-12-14
@libera

Well, what's the problem? The task is simple to the primitive.

string s1,s2;
foreach(var item in File.ReadAllLines())
{
var t = item.Split(':')
s1+= t[0]
s2+= t[1]
}
textBox1.Text = s1;
textBox2.Text = s2;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question