Work on C#.I have a list named as InputList .From this list I have to search Some string.After search I want to select all item between the search parameter.Bellow picture discribe in detail.
Text Input File:
Collection :
After read the textFile I store data in dataset then,convert the dataset as collection .From this collection i want to get valuse between the search parameters.
I write the bellow syntax but r3 result can not satisfy me.
var InputList = (from p in ds.Tables["InputFile"].Rows.Cast<DataRow>().ToArray() select p.ItemArray).ToL开发者_运维知识库ist();
var r3 = (from c in InputList
where c.Any(e => e.ToString().Contains("Loading"))
select c).ToList();
If have any query plz ask.Thanks in advance.
To get the results between queries, the SkipWhile()
and TakeWhile()
would work (both have variants that give the index to the predicate), but I don't think that is quite what you want given your image.
var loadingIndexes = InputList.Select((r, i) => new { Row=row, Index=i })
.Where(x => x.Row.Any(e =>
e.ToString().Contains("Loading"))
.Select(x => x.Index);
var betweenLines = loadingIndexes
.Select(i => InputList
.Skip(i)
.TakeWhile(r => !r.Any(e =>
e.ToString().Contains("FULL")))
.ToList())
.ToList();
Here betweenLines
is a List
of List
s of DataRow
s, where each list is between a DataRow
containing the string "Loading" (inclusive) and the next `DataRow" containing the string "FULL" (exclusive).
精彩评论