Find strings following a pattern in a text file using C# -
i'm looking way search through huge text file , extract couple of strings follow pattern, write each of strings individual lines in text file.
is there equivalent of linux grep
command, combined *
, -
, ^
, []
, etc. symbols in c# ?
i hope place type of open questions. thank !
firstly, if it's large file, use file.readlines()
scan lazy loads small amounts of data @ time, giving 1 line @ time process.
then match items, use c#'s regular expression functionality.
you'll end like:
var regex = new regex(-- match expression --); foreach (var line in file.readlines("somefile").where(line => regex.match(line).success)) { file.appendalltext("file write to", line + environment.newline); }
Comments
Post a Comment