Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use LINQ to get the number of duplicate lines. This will create a dictionary that contains the string as the <code>key</code> and the number of times that string appears as the <code>value</code>.</p> <pre><code>var lineCountDict = lines.GroupBy(x =&gt; x).ToDictionary(x =&gt; x.Key, x =&gt; x.Count()); </code></pre> <p>To read out the values, simply iterate through the dictionary So, using your example list</p> <pre><code>List&lt;String&gt; lines = new List&lt;string&gt;() { "a bag of coins", "a siog brandy", "a bag of coins", "a bag of coins", "the Cath Shield", "a tattered scroll" }; var lineCountDict = lines.GroupBy(x =&gt; x).ToDictionary(x =&gt; x.Key, x =&gt; x.Count()); foreach (var val in lineCountDict) { Console.WriteLine(val.Key + " - " + val.Value); } </code></pre> <p>This will output each string and how many times it appeared, including those strings that only appear once. If you only want those that are duplicates, you can modify the LINQ query by adding a <code>Where</code>clause</p> <pre><code>var lineCountDict = lines.GroupBy(x =&gt; x).Where(x =&gt; x.Count() &gt; 1).ToDictionary(x =&gt; x.Key, x =&gt; x.Count()); </code></pre> <p>The dictionary will then have only one item from the list in your example (<code>a bag of coins</code>) and the key would be <code>a bag of coins</code> and the value would be <code>3</code> since it appears 3 times.</p> <p><strong>update based on comments</strong></p> <p>This should work in your case</p> <pre><code>List&lt;string&gt; modifiedList = new List&lt;string&gt;(); int numberOfDrops = 0; foreach (string line in lines.Where(l =&gt; l.Length &gt;= 5)) { string ad = line.Remove(0, 11); if ((ad.Contains(mobName) &amp;&amp; ad.Contains("dies"))) { mobDeathCount++; } if (ad.Contains(mobName) &amp;&amp; ad.Contains("drops")) { string lastpart = ad.Substring(ad.LastIndexOf("drops")); string modifiedLastpart = lastpart.Remove(0, 6); modifiedList.Add(modifiedLastpart); numberOfDrops++; } } double deathDropRatio = (double)mobDeathCount / (double)numberOfDrops; var lineCountDict = modifiedList.GroupBy(x =&gt; x).Where(x =&gt; x.Count() &gt; 1).ToDictionary(x =&gt; x.Key, x =&gt; x.Count()); foreach (var val in lineCountDict) { Console.WriteLine(val.Key + " - " + val.Value); } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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