Pages

Jan 28, 2008

How to compare 2 arraylist and find the one is the sublist of the other in c#


using System;
using System.Collections.Generic;

list declaration:
List RecipIDList = new List(new int[] { 1,2,3,4, 5, 7 });
List subList = new List(new int[] { 4, 5, 7 });


Function that does actual process:
// to find that the 2nd list is the sublist of the first one

public static string IndexOf(List RecipIDList, List subList)
{
int recipCount = 0;
int j = 0;
while (j < recipcount ="="">

Comparing 2 arrays and finding missing Items

//Gets a list of the items in an array missing from a second array.

using System.Collections;

public ArrayList GetMissingItems(string[] allItems, ArrayList someItems)
{
ArrayList missingItems = new ArrayList();
for (int i=0; i
{
if ( allItems[i].Trim().Length > 0 ) //filter out empty strings
{
if ( !someItems.Contains(allItems[i].Trim()) )
{
missingItems.Add(allItems[i]);
}
}
} return missingItems;
}