title: Find the index position of duplicate entries in a comma separated string
body: <p>My problem just got more complicated than I thought and I've just wiped out my original question... So I'll probably post multiple questions depending on how I get on with this.</p>
  
  <p>Anyway, back to the problem. I need to find the index position of duplicate entries in string that contains csv data. For example,</p>
  
  <p>FirstName,LastName,Address,Address,Address,City,PostCode,PostCode, Country</p>
  
  <p>As you can see the Address is duplicated and I need to find out the index of each duplicates assuming first index position starts at 0.</p>
  
  <p>If you have a better suggestion on how to do this, let me know, but assuming it can be done, could we maybe have with a dicitionary>?</p>
  
  <p>So if I had to code this, you would have:</p>
  
  <pre><code>duplicateIndexList.Add(2);
  duplicateIndexList.Add(3);
  duplicateIndexList.Add(4);
  
  myDuplicateList.Add("Address", duplicateIndexList);
  
  duplicateIndexList.Add(6);
  duplicateIndexList.Add(7);
  
  myDuplicateList.Add("PostCode", duplicateIndexList);
  </code></pre>
  
  <p>Obviously I don't want to do this but is it possible to achieve the above using Linq to do this? I could probably write a function that does this, but I love seeing how things can be done with Linq.</p>
  
  <p>In case you're curious as to why I want to do this? Well, in short, I have an xml definition which is used to map csv fields to a database field and I want to first find out if there are any duplicate columns, I then want to append the relevant values from the actual csv row i.e. Address = Address(2) + Address(3) + Address(4), PostCode = PostCode(6) + PostCode(7)</p>
  
  <p>The next part will be how to remove all the relevant values from the csv string defined above based on the indexes found once I have appended their actual values, but that will be the next part.</p>
  
  <p>Thanks.</p>
  
  <p>T.</p>
  
  <h2>UPDATE:</h2>
  
  <p>Here is the function that does what I want but as I said, linq would be nice. Note that in this function I'm using a list instead of the comma separated string as I haven't converted that list yet to a csv string.</p>
  
  <pre><code>Dictionary&lt;string, List&lt;int&gt;&gt; duplicateEntries = new Dictionary&lt;string, List&lt;int&gt;&gt;();
  
  int indexPosition = 0;
  foreach (string fieldName in Mapping.Select(m=&gt;m.FieldName))
  {
   string key = fieldName.ToUpper();
   if (duplicateEntries.ContainsKey(key))
     {
        List&lt;int&gt; indexes = duplicateEntries[fieldName];
        indexes.Add(indexPosition);
        duplicateEntries[key] = indexes;
        indexes = null;
     }
   else
     {
       duplicateEntries.Add(key, new List&lt;int&gt;() { indexPosition });
     }
   indexPosition += 1;
  }
  </code></pre>
  
  <p>Maybe this will help clarify what I'm trying to achieve.</p>