ArrayList Help Needed for Newbie...
-
I'm aware of how to use arrays similar to the following example. static void Main() { ArrayList list = new ArrayList(); list.Add(45); list.Add(87); list.Add(12); foreach(int num in list) { Console.WriteLine(num); } } However, I'm trying to capture data strings from a log server and parse them in memory rather than FileStreaming them to a log.txt file and parsing later. I can view the ArrayList activity with a listBox and it seems to me it only holds one (1) string at a time. I need a growing list in memory that I can sort and parse. Here's my failing setup so far. Help...... (C#) str = System.Text.Encoding.ASCII.GetString(data); //data is a Byte[] Al = new ArrayList(1024); Al.Add(str); foreach(string Line in Al) { listBox1.Items.Add(Line.ToString()); } // Knowledge is a one way street, Wisdom is looking both ways before crossing :)
-
I'm aware of how to use arrays similar to the following example. static void Main() { ArrayList list = new ArrayList(); list.Add(45); list.Add(87); list.Add(12); foreach(int num in list) { Console.WriteLine(num); } } However, I'm trying to capture data strings from a log server and parse them in memory rather than FileStreaming them to a log.txt file and parsing later. I can view the ArrayList activity with a listBox and it seems to me it only holds one (1) string at a time. I need a growing list in memory that I can sort and parse. Here's my failing setup so far. Help...... (C#) str = System.Text.Encoding.ASCII.GetString(data); //data is a Byte[] Al = new ArrayList(1024); Al.Add(str); foreach(string Line in Al) { listBox1.Items.Add(Line.ToString()); } // Knowledge is a one way street, Wisdom is looking both ways before crossing :)
You've only added one string to the arrayList, so how many were you hoping would come out ? If there is a seperator in the byte[] that denotes the position of multiple strings, then use the Split function of the string class to turn str into a String[], which you can then foreach into the listbox. Assuming your delimiter is a slash or something, otherwise you may have to parse the byte array instead. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
I'm aware of how to use arrays similar to the following example. static void Main() { ArrayList list = new ArrayList(); list.Add(45); list.Add(87); list.Add(12); foreach(int num in list) { Console.WriteLine(num); } } However, I'm trying to capture data strings from a log server and parse them in memory rather than FileStreaming them to a log.txt file and parsing later. I can view the ArrayList activity with a listBox and it seems to me it only holds one (1) string at a time. I need a growing list in memory that I can sort and parse. Here's my failing setup so far. Help...... (C#) str = System.Text.Encoding.ASCII.GetString(data); //data is a Byte[] Al = new ArrayList(1024); Al.Add(str); foreach(string Line in Al) { listBox1.Items.Add(Line.ToString()); } // Knowledge is a one way street, Wisdom is looking both ways before crossing :)
just bind the arraylist's datasource and dont add/remove items to the listbox itself eg.
listBox1.DataSource = Al;
SHould be all you need. Look at the help too, if you want to customise the display of the listbox (something member (datamember?) property). :) top secret xacc-ide 0.0.1