根据另一个字符串列表显示字符串列表 [英] Extarct a list of strings based on another list of strings

查看:84
本文介绍了根据另一个字符串列表显示字符串列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

List1: {"123456", "432978", "321675", …}  // containing 100,000 members




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



我想在List2中提取他们的前6位数字来自List1成员的所有项目,所以这里的字符串1234568897是有效的,因为它的前6位是来自List1的第一个项目。这是最快的方法吗?


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?

推荐答案



你可以达到以下目的:



Hi,
you can achieve this as below:

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]));





因此,您的第一个列表是密钥,第二个列表是您要搜索的,第三个列表是搜索的结果。



问候

Jegan



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


这篇关于根据另一个字符串列表显示字符串列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆