![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Dec 2006
Posts: 41
Rep Power: 0
![]() |
Help Indexing ArrayList
Hey everyone I have made an arraylist that takes a stream of information from a string I have made that contains some IP addresses. However I am having a problem assigning the information correctly to my ArrayList. Each IP address is approxiamtely 13 characters long. Here is my code..
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. For example it starts out doing "index[0] = 150.542.234.23 index[1] = 45.543.245.21 index[2] = 4.342.233.29..etc.." because the i is incrementing by one which is making the starting index go up by one everytime. How would I make it so it records all 13 characters of Each IP adress? |
|
|
|
|
|
#2 | |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
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:
I'm not familiar with C#, but in VB it would look something like this: vb Syntax (Toggle Plain Text)
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 6:59 AM. |
|
|
|
|
|
|
#3 |
|
Not a user?
Join Date: Sep 2007
Posts: 245
Rep Power: 1
![]() |
Re: Help Indexing ArrayList
I tried to convert this to C# but I don't know enough about it to really do it.
c# Syntax (Toggle Plain Text)
I get all kinds of errors about my strings and arrays, but maybe it'll help you out at least a little bit. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
Re: Help Indexing ArrayList
Use this code with your variables.... remember to replace the comma in the split call with your delimiter.
C# Syntax (Toggle Plain Text)
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 143
Rep Power: 4
![]() |
Re: Help Indexing ArrayList
Or just use i=i+13 in your loop?
If you KNOW each IP is 13 characters, and you don't have a delimiter... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ArrayList Start Index | kruptof | C# | 8 | Sep 2nd, 2007 10:20 AM |
| Problem with an ArrayList | Twilight | C# | 2 | Apr 25th, 2006 1:15 PM |
| ArrayList and MSDN | Writlaus | C++ | 13 | Apr 5th, 2006 3:27 AM |
| ArrayList Troubles | crawforddavid2006 | Java | 17 | Jan 10th, 2006 6:37 PM |
| Converting object to arraylist | yusufozkay | C# | 1 | Jul 18th, 2005 8:08 AM |