comparing two arrays
-
hi, i have two arrays.. first arraylist consists of 1,2,4,6,8; second arraylist consists of 2,6,9,8 i got the commoon items using the following code..it is working fine for(int i=0;i<strOldItems.Length;i++) { strTest[i]=strOldItems[i]; for(int j=0;j<strNewItems.Length;j++) { if(strTest[i]==strNewItems[j]) { if(strCommon.Length>0) { strCommon=strCommon+","+ strTest[i]; //Response.Write(strTest[i]+","); } else { strCommon=strTest[i]; } } but i need the items which is in first array and which is not in second array..for that i wrote the following code..but it is not working.. for(int i=0;i<strOldItems.Length;i++) { strTest[i]=strOldItems[i]; for(int j=0;j<strNewItems.Length;j++) { if(strTest[i]!=strNewItems[j]) { if(strReject.Length>0) { strReject=strReject+","+ strTest[i]; //Response.Write(strTest[i]+","); } else { strReject=strTest[i]; } } } }
-
hi, i have two arrays.. first arraylist consists of 1,2,4,6,8; second arraylist consists of 2,6,9,8 i got the commoon items using the following code..it is working fine for(int i=0;i<strOldItems.Length;i++) { strTest[i]=strOldItems[i]; for(int j=0;j<strNewItems.Length;j++) { if(strTest[i]==strNewItems[j]) { if(strCommon.Length>0) { strCommon=strCommon+","+ strTest[i]; //Response.Write(strTest[i]+","); } else { strCommon=strTest[i]; } } but i need the items which is in first array and which is not in second array..for that i wrote the following code..but it is not working.. for(int i=0;i<strOldItems.Length;i++) { strTest[i]=strOldItems[i]; for(int j=0;j<strNewItems.Length;j++) { if(strTest[i]!=strNewItems[j]) { if(strReject.Length>0) { strReject=strReject+","+ strTest[i]; //Response.Write(strTest[i]+","); } else { strReject=strTest[i]; } } } }
Did you check by applying the break point aah? did you get the value or not? And what error it shows?
SSK. Anyone who says sunshine brings happiness has never danced in the rain.
-
Did you check by applying the break point aah? did you get the value or not? And what error it shows?
SSK. Anyone who says sunshine brings happiness has never danced in the rain.
hi, it is not giving any error, to get the same values from the two arrays ..i wrote the logic like this, first array first element checks with all the second array elemnts..if it find any matches ..it returns the matched value..like second element with all the elements of second array. but to get the elemenet which is in first array and which is not second array.. i wrote like this, first array element checks with the all the elements in the second array..if he does not found any matches it returns the unmatched values ....this is wrong na..becasue this first elemnt unmacthedvalues may be equal to the second element in the first array how can i write the logic for this