Reputation: 47
this is my text data in .txt file
G300#Logitech#Mouse
G500#Logitech#Mouse
G1010#Logitech#Mouse
and I want to read it and place it in text box I have tried but it just show the last line I want to write all the line
this is my code:
List<string> lines = new List<string>();
using (TextReader tr = new StreamReader(@"databarang.dat"))
{
string line;
while ((line = tr.ReadLine()) != null)
{
lines.Add(line);
}
foreach (string s in lines)
{
txtOutput.Text = s + "\n";
}
}
and this is my layout program
and how can I split the '#' and write it in text box so in the text box it must be
G300 Logitech Mouse
G500 Logitech Mouse
G1010 Logitech Mouse
Upvotes: 0
Views: 715
Reputation: 3571
Try using
txtOutput.AppendText(s + Environment.NewLine);
You can split a string based on the hash as shown below
string[] parts = "G300#Logitech#Mouse".Split('#');
Upvotes: 1
Reputation: 1537
You can do as shown below.
This way you can be able to get the rows as you need.
Upvotes: 2