Hi, i'm new to C#.
I need my program to show different parts of the data contained in a txt file into different listboxs (which are on different tabs of a form) so that the user can see the particular block of data they are interested in.
the data contained in the txt file looks like this:
G30:39:03:31 JG06
G32:56:36:10 JG04
G31:54:69:52 JG04
G36:32:53:11 JG05
G33:50:05:11 JG06
G39:28:81:21 JG01
G39:22:74:11 JG06
G39:51:44:21 JG03
G39:51:52:22 JG01
G39:51:73:21 JG01
G35:76:24:20 JG06
G35:76:55:11 JG01
G36:31:96:11 JG02
G36:31:96:23 JG02
G36:31:96:41 JG03
though much more of it :)
The separate listboxes will contain only the lines who's first integer pair matches that listbox's name. For example, all the lines that start "G32" will be added to the G32 listbox.
I think the code would start something like:
private void ReadToBox()
{
FileInfo file = new FileInfo("Jumpgate List.JG");
StreamReader objRead = file.OpenText();
while (!objRead.EndOfStream)
but i'm not sure where to start in terms of getting it sorted yet.
Any help? There's some rep in it for you :D
EDIT:
private void ViewForm_Load(object sender, EventArgs e)
{
this.PopulateListBox(lstG30, "G30", ("Jumpgate List.JG"));
this.PopulateListBox(lstG31, "G31", ("Jumpgate List.JG"));
this.PopulateListBox(lstG32, "G32", ("Jumpgate List.JG"));
this.PopulateListBox(lstG33, "G33", ("Jumpgate List.JG"));
this.PopulateListBox(lstG34, "G34", ("Jumpgate List.JG"));
this.PopulateListBox(lstG35, "G35", ("Jumpgate List.JG"));
this.PopulateListBox(lstG36, "G36", ("Jumpgate List.JG"));
this.PopulateListBox(lstG37, "G37", ("Jumpgate List.JG"));
this.PopulateListBox(lstG38, "G38", ("Jumpgate List.JG"));
this.PopulateListBox(lstG39, "G39", ("Jumpgate List.JG"));
}
void PopulateListBox(ListBox lb, string prefix, string textfile)
{
string[] filestrings = textfile.Split(Environment.NewLine.ToCharArray());
foreach(string line in filestrings)
{
if (line.StartsWith(prefix))
lb.Items.Add(line);
}
}