Requesting a specific line from a txt file in C #

I have the following text file: http://pastebin.com/K45Ew5CU

I would like to make a specific query that takes rows from a specific minute and puts them in a data grid that has an object (String TimeStamp, String ComputerName, String ID, String Event) as data fields.

For example: Lets say that I would like to display all the lines from 10:10:00 to this current time.

How to check each line to see if it meets my time requirements?

+4
source share
1 answer

Use this:

var queryResult = File.ReadAllLines("<yourFile.txt>").Skip(1).TakeWhile(x => (DateTime.Parse(x.Substring(0, 19), CultureInfo.InvariantCulture).TimeOfDay.TotalSeconds) > (new TimeSpan(10, 10, 0).TotalSeconds)).ToArray();

queryResult . , .

:

var queryResult = File.ReadAllLines("<yourFile.txt>")
                      .Skip(1)
                      .TakeWhile(x => (DateTime.Parse(x.Substring(0, 19), CultureInfo.InvariantCulture).TimeOfDay.TotalSeconds) > (new TimeSpan(10, 10, 0).TotalSeconds))
                      .Select(x => new { TimeStamp = DateTime.Parse(x.Substring(0, 19), CultureInfo.InvariantCulture), CoumputerName = x.Substring(21, 10), ID = x.Substring(45, 4), Event = x.Substring(59)})
                      .ToArray();

queryResult.

+6

Source: https://habr.com/ru/post/1629684/


All Articles