View Single Post
Old Mar 31st, 2008, 7:33 AM   #2
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 308
Rep Power: 2 Jabo is on a distinguished road
Re: Help Indexing ArrayList

why would you not split your string into the array? I don't know how getnearbysystems populates the string, but it should separate the ip addresses somehow, and you can use that delimiter to split your string into usable array entries

Quote:
Originally Posted by csrocker101 View Post
string IPAdressesofSystems = service.GetNearbySystems(host);
            ArrayList newList = new ArrayList();

            for (int i = 0; i < IPAdressesofSystems.Length; i++)
            {
                newList.Add(IPAdressesofSystems.Substring(i, 13));
            }

I am well aware it's because of the "i" index I am using in my Substring method is starting at the next incremented index.
What this code does is what you said. If you use the string.split method to separate your string, it will look for whatever delimiter you specify.

I'm not familiar with C#, but in VB it would look something like this:
vb Syntax (Toggle Plain Text)
  1. Dim str1 As String = "xyz,pbb7,rx78"
  2. Dim str2() As String
  3. str2 = str1.Split(",")
  4. For x As Integer = 0 To str2.Length - 1
  5. MsgBox(str2(x), MsgBoxStyle.Information, "Array")
  6. Next

This way, it don't matter what the size of each individual string is. The code I posted displays each array element in a new message box.

Last edited by Jabo; Mar 31st, 2008 at 7:59 AM.
Jabo is offline   Reply With Quote