C# reading file contents and finding strings -


I'm real new to C #. Under some directories, I open a bunch of code files and get some lines that contain some mailing strings. It's a simple problem, I can open files once by using the Stream Reader and then parse them by line. I was wondering if there is a more efficient way to do this. As I am under the assumption that line reading will be a heavy action to read the stream reader and line.

How to get some good post files already, so I thought I Some people will add a little about some people have mentioned the file. ReadAllLines () method This method is problematic in terms of efficiency because it will read the entire file in memory at one time. In addition, it uses storage as an array in which proximal memory is required, if the file is sufficiently large then problems will arise.

A more efficient way to read files is to use the StreamReader.ReadLine method repeatedly. It will return one line at a time and you need to keep the lines to be remembered. It's easy to turn it on in a delayed evaluator repeater.

Public Fixed IEnumerable & lt; String & gt; ReadLinesEnumerable (string path) {(var reader = new streamrider (path)) {var line = reader.ReadLine (); While (line! = Null) {yield returns line; Line = reader. Readline (); In the context of LINQ you can use LINQ to match both readAllLines and ReadLinesEnumerable method equally, because both return a numerical data type. For example, from line in
  var query = ReadLinesEnumerable (@ "c: \ some \ path \ file.txt") where Regex.IsMatch (line, @ "^ (\ d) + . * $ ") Select line;  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -