Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
List1: {"123456", "432978", "321675", …}  // containing 100,000 members

C#
List2: {"7674543897", "1234568897", "8899776644",…} // containing 50,000 members

I want to extract all items in List2 that their first 6 digits are from List1 members, so here the string “1234568897” is valid because its first 6 digits are from List1’s first item. What it the fastest way of doing this?
Posted
Comments
CHill60 6-Mar-13 6:55am    
Given the number of members you suggest are in each list where are you getting these "strings" from ?

1 solution

Hi,
you can achieve this as below:

C#
List<string> list1 = new List<string>();
list1.Add("123456");
list1.Add("432978");
list1.Add("321675");

List<string> list2 = new List<string>();
list2.Add("7674543897");
list2.Add("1234568897");
list2.Add("8899776644");

List<string> list3 = list2.FindAll(x => x.StartsWith(list1[0]));


So you have your first list that are the keys, and the second list that you are searching for and the third list that is the searched results.

Regards
Jegan
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900