c# - Searching in text files for a keyword until a string is encountered -
i'm writing program me search keyword inside thousands of files. each of these files has unnecessary lines need ignore because mess results. luckily they're located after specific line inside files.
i've got search, without ignoring lines after specific line, returning enumerable of file names containing keyword.
var searchresults = files.where(file => file.readlines(file.fullname) .any(line => line.contains(keyword))) .select(file => file.fullname);
is there simple , fast way implement functionality? doesn't have in linq i'm not sure if possible.
edit:
example make clearer. how text files structured:
xxx
xxx
string
yyy
yyy
i want search xxx lines until either keyword found or string , skip next file. yyy lines want ignore in search.
try this:
var searchresults = files.where(file => file.readlines(file.fullname) .takewhile(line => line != "stop") .any(line => line.contains(keyword))) .select(file => file.fullname);
Comments
Post a Comment