There is a collection in the collection of the line of the form:

stud1/name1?a=lend1223 stud/name2?b=lend356 stud/name3?v=lend56 

it is necessary to remove all duplicate rows from this collection strictly for this part: "? a =", that is, from the symbol: " ? " to the symbol: " = "

How is it possible to implement it easier?

    3 answers 3

    Select the items in the key, which will be cut off duplicates. Group by this key. Select one item from each group.

     List<string> list = new List<string>(){ "stud1/name1?a=lend1223", "stud/name12?a=lend1223", "stud/name2?b=lend356", "stud/name22?b=lend356", "stud/name3?v=lend56" }; List<string> nlist = list.Select(p => new { key = new Regex("\\?(.)*=", RegexOptions.IgnoreCase).Match(p).Groups[1].Value, value = p }) .GroupBy(p => p.key) .Select(p => p.First().value) .ToList(); 
       collection.Where((x, i) => collection.Where((y, j) => j < i && y.Contains( x.Substring(x.IndexOf("?"), 1 + x.IndexOf("=") - x.IndexOf("?")))).Count() == 0); 
         string x = "bla-bla-bla"; int pos, pos2; while ((pos = x.IndexOf('?')) !=-1 && ((pos2 = x.IndexOf('=')) !=-1)) x = x.Substring(0,pos-1)+x.Substring(pos2+1);