Hey guys,

I'm a bit stuck with this issue...

I have a list of comma separated strings.

some of them have a duplicate field in them.

what I want at the end of this process is a List of strings (comma seperated again) with any of the duplicates being marked with a number (ideally 1 for the first duplicate, 2 for the 2nd etc.). The number needs to be appended to a different field to the field i'm checking for duplicates in.

this is what i've tried... it makes each one unique but i only want to append x to the duplicate values

int x = 0;
            foreach (string PugString in PUGList)
            {    
                string[] PugDeets = PugString.Split(',');
                PugDeets[7] = PugDeets[6].Replace(" ","_") +"_"+ "Default";
                foreach (string subPugString in PUGList)
                {
                    string[] SubPugDeets = subPugString.Split(',');

                    if (SubPugDeets[6] == PugDeets[6])
                    {
                        PugDeets[7] += x.ToString();
                        x++;
                    }
                }
                string tempstring = String.Join(",", PugDeets,0,PugDeets.Count());
                
                FinalPUGList.Add(tempstring);
                     
            }

I hope this makes some sort of sense!

I understand why this doesnt do what i want but i cant work out how to get what i'm after!

d'oh...

i was being thick...

i just made a 2nd list and added each new value to the list if it wasn't already there.

in case anyone is curious...

List<string>TempPug= new List<string>();
            TempPug.Add("Starter");
            
            foreach (string PugString in PUGList)
            {
                int foundcount = 1;
                string[] PugDeets = PugString.Split(',');
                if (PugDeets.Count() > PugMemberCount) PugMemberCount = PugDeets.Count();
                PugDeets[7] = PugDeets[6].Replace(" ", "_") + "_" + "Default";
                for (int l = 0;l<=TempPug.Count()-1;l++)
                {
                    if (PugDeets[6] == TempPug[l].ToString())
                    {
                        foundcount++;
                    }
                }
                if (foundcount == 1) TempPug.Add(PugDeets[6].ToString());
                else
                {
                    PugDeets[7] += "-" + foundcount;
                }
                string tempstring = String.Join(",", PugDeets, 0, PugDeets.Count());
                FinalPUGList.Add(tempstring);
            }
This question has already been answered. Start a new discussion instead.