我该如何搜索子串的名单 [英] How can I search a Substring in a List
问题描述
我的问题是我在这串名单。这些字符串是PROGRAMM名。 所以,当我在列表,例如办公室搜索他没有发现任何东西,因为我有搜索的全称微软Office专业增强版2013
那么,如何寻找一个子串,并且可以返回全名的问题
例如: 我的搜索词是办公室。
而当列表中包含微软Office专业增强版2013(或任何其他版本)的全名应退还
的for(int i = 0; I< InstalledProgramms.Count;我++)
{
如果(installedProgramms [我] ==办公室)
{
办公室= list.ElementAt(ⅰ);
}
}
尝试是这样的:
的String [] LANGS =新的String [] {C ++,Java的,Perl的,序言,微软Office专业增强版2013,};
VAR lang_list =新的名单,其中,串>(LANGS);
字符串search_word =办公室;
//发现有你的搜索词的第一语言
变种郎= lang_list.First(升=> l.IndexOf(search_word,StringComparison.InvariantCultureIgnoreCase)-1)〜.ToArray();
//查找所有匹配郎
变种all_lang = lang_list.Where(升=> l.IndexOf(search_word,StringComparison.InvariantCultureIgnoreCase)-1)〜.ToArray();
My Problem is i have a list with strings in it. These strings are programm names. So when I search in the List for example "Office" he didnt found anything because i have to search for the full name "Microsoft office Professional Plus 2013"
So the question how can i search for a Substring and can return the full name
For Example: My search word is Office.
And when the list contains "Microsoft office Professional Plus 2013"(or any other version) then the full name should be returned
for (int i = 0; i < InstalledProgramms.Count; i++)
{
if (installedProgramms[i] == "Office")
{
office = list.ElementAt(i);
}
}
try something like this :
string[] langs = new string[] { "C++", "Java", "Perl", "Prolog", "Microsoft office Professional Plus 2013", };
var lang_list = new List<string>(langs);
string search_word = "office";
// finding first language that has your search word
var lang = lang_list.First(l => l.IndexOf(search_word, StringComparison.InvariantCultureIgnoreCase) > -1).ToArray();
// find all matching lang
var all_lang = lang_list.Where(l => l.IndexOf(search_word, StringComparison.InvariantCultureIgnoreCase) > -1).ToArray();
这篇关于我该如何搜索子串的名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!