Note that there are some explanatory texts on larger screens.

plurals
  1. POCombining numbers and names collections
    primarykey
    data
    text
    <p>I have 2 List collections. One contains numbers, the other names. There are twice as many numbers as names(always). I want to take the first name from the collection and the first two numbers from the other collection then put them together in a 3rd user collection of (VentriloUser). Then the second name needs to be matched with the 3rd and 4th numbers and so on.</p> <p>I was thinking something with a for or foreach loop, but I can't wrap my head around it right now.</p> <pre><code>public class VentriloUser { public VentriloUser(string name, int seconds, int ping) { Name = name; Seconds = seconds; Ping = ping; } public string Name { get; set; } public int Ping { get; set; } public int Seconds { get; set; } } public class Ventrilo { public Ventrilo(string statusurl) { StatusURL = statusurl; } public string StatusURL { get; set; } public string HTML { get; set; } public List&lt;VentriloUser&gt; Users { get; set; } private Regex findNumbers = new Regex("\\&lt;td width=\"10%\" bgcolor=\"#\\w{6}\"\\&gt;\\&lt;font color=\"#000000\"&gt;\\&lt;div style=\"overflow:hidden;text-overflow:ellipsis\"\\&gt;-?\\d+\\&lt;"); private Regex findNames = new Regex("\\&lt;td width=\"20%\" bgcolor=\"#\\w{6}\"\\&gt;\\&lt;font color=\"#000000\"&gt;\\&lt;div style=\"overflow:hidden;text-overflow:ellipsis\"\\&gt;\\b\\w+\\&lt;"); private WebClient wClient = new WebClient(); public void DownloadHTML() { HTML = wClient.DownloadString(StatusURL); } public List&lt;int&gt; GetNumbers() { var rawnumbers = findNumbers.Matches(HTML); var numbers = new List&lt;int&gt;(); foreach (var rawnumber in rawnumbers) { var match = Regex.Match(rawnumber.ToString(), "\\&gt;\\-?\\d+\\&lt;"); string number = Regex.Replace(match.ToString(), "\\&lt;|\\&gt;", ""); numbers.Add(Convert.ToInt32(number)); } return numbers; } public List&lt;string&gt; GetNames() { var rawnames = findNames.Matches(HTML); var names = new List&lt;string&gt;(); foreach (var rawname in rawnames) { var match = Regex.Match(rawname.ToString(), "\\&gt;\\w+&lt;"); string name = Regex.Replace(match.ToString(), "\\&lt;|\\&gt;", ""); names.Add(name); } return names; } public List&lt;VentriloUser&gt; GenerateUsers() { var numbers = GetNumbers(); var names = GetNames(); var users = new List&lt;VentriloUser&gt;(); } } </code></pre> <p>I am a hobbyist, but hope to pursue a career one day. Any help is much appreciated. Thank you for your time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload