Hello im trying to write a searchtool for filenames which allow to search with multiple words. At the moment i can just search for one word but i want to filter my results with more words combined.
here is my code so far:
public List<String> startYareSearch(string query, string source)
{
List<String> SearchResultList = new List<String>();
List<String> FileNameList = getFileNames(source);
foreach (string fileName in FileNameList)
{
if (fileName.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)
{
SearchResultList.Add(fileName);
continue;
}
}
return SearchResultList;
}
i think that i need an function which recieves the queries from an array and generate a dynamic if condition.
for an example:
String[] queries= new string[] { "Tobias", ".txt"};
String fileName= "blablaTobiasbla.txt";
if (fileName.IndexOf("Tobias", StringComparison.OrdinalIgnoreCase) >= 0 || fileName.IndexOf(".txt", StringComparison.OrdinalIgnoreCase) >= 0)
{
SearchResultList.Add(fileName);
continue;
}
is it possible to create an if condition dynamically? Do you know a better solution?
Aucun commentaire:
Enregistrer un commentaire