Okay, so the below should accomplish this, and I know there are other ways to accomplish this as well, but this should get you started
Code:
var ipAddresses = new List<List<string>>();
using (StreamReader sr = new StreamReader("C:\\ipaddresses.txt"))
{
string ipAddress;
int ipAddressLocation;
int ipAddressCount = 1;
// Read to the end of the file
while(!sr.EndOfStream)
{
// Read the ip address
ipAddress = sr.ReadLine();
// Determine which array the ip address should be part of
ipAddressLocation = (int)Math.Floor(ipAddressCount/30.0);
// Check that the array exists, otherwise, create it
if (ipAddresses.Count <= ipAddressLocation)
{
ipAddresses.Add(new List<string>());
}
// Add the ip address to its' array
ipAddresses[ipAddressLocation].Add(ipAddress);
ipAddressCount++;
}
}
Bookmarks