hey, i have 2 listboxs (listbox1 and listbox2), both the listboxs contains output as following:

listbox1
1 2
1 4
1 5
1 2 4
2 4 5

listbox2
1 2 2 4 5
1 3 4 5


I wants to compare the 2 listboxs, for each line of listbox1, if listbox2 contains the number, then it will count the occurences by +1, for example:
for that 1 2 ,if it includes in the first line of listbox2 (1 2 2 4 5), then it will +1, after that it will look to line 2, if does not included, then i will continue to next line, and so on. finally i wants add to the sortedlist.

foreach (string sortComb in listbox1 .Items)
            {
               
                foreach (string ext in listbox2.Lines)
                {                     
                    if (ext.Contains(sortComb))
                    {
                        // how to write the statement??                
                    }       
                          
                }
              sortList2.Add(sortComb, ??);
int occurance;

foreach (string sortComb in listbox1 .Items)
            {
               occurance=0;
                foreach (string ext in listbox2.Lines)
                {                     
                    if (ext.Contains(sortComb))
                    {
                        occurance++;         
                    }       
                          
                }
MessageBox.Show( sortComb+" Exits "+ ocuurance+" times in list2");

}

this was simple now please explain in sorted list what you want to add? mean do you want to add whole the second list or only those sub-strings which were also in list 1

I just wants to add the substring ( 1 2 ), the sortedlist should have the substring as key and occurences ass values.
I had tried your codes but the occurences seems like add nothing, it just 0 in the messagebox, why would like that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.