score:2
Accepted answer
You could set a flag in TakeUntil
that indicates that you are past #define BYE
:
bool byeFlag = false;
var p = from line in File.ReadLines(file)
.SkipWhile(l => l.TrimStart() != ("#define HELLO"))
.TakeUntil(l =>
{
bool ret = byeFlag;
if (l.TrimStart() == "#define BYE")
{
byeFlag = true;
}
return ret;
})
.ToList()
select new
{
File = file,
Line = line
};
But as already mentioned, maybe LINQ is not really the best tool for what you are trying to do. Maybe parsers like ANTLR are better suited for the job?
Source: stackoverflow.com
Related Articles
- Retrieve strings from a file, filtering with Linq when multiple lines contain the exact same string
- Filtering folders from a list when using LINQ to sort to find the oldest file
- How to retrieve multiple rows from a stored procedure with Linq to SQL?
- How to ignore blank lines with linq when importing from CSV.
- LINQ Join with Multiple From Clauses
- How to remove an element from an xml using Xdocument when we have multiple elements with same name but different attributes
- Removing characters from strings with LINQ
- LINQ to SQL: Complicated query with aggregate data for a report from multiple tables for an ordering system
- How to reuse a linq expression for 'Where' when using multiple source tables
- How does linq actually execute the code to retrieve data from the data source?
- How to create a list from filtering 2 lists with linq to object
- When selecting an anonymous type with LINQ from EF, is there no way to run a method on an object as you select it?
- How to use LINQ to query list of strings that do not contain substring entries from another list
- LINQ on Directory.GetFiles with filtering and sorting with multiple sort criteria
- Multiple level where clause filtering with Linq
- Select data from multiple unrelated tables with LINQ to Entity Framework
- Retrieve and print data from dynamic sql query with linq
- Linq select strings from list when condition is met and save the index
- How to select multiple columns from dataset into a string list with LinQ
- Linq filtering results with multiple Where clauses
- Populate a C# class from a dataset with multiple linked tables using linq lambda
- creating Linq to sqlite dbml from DbLinq source code
- How to format linq to replace AND with OR when combining multiple Where's
- Reading values from xml file with Linq
- Linq sub query when using a repository pattern with EF code first
- Retrieve the node values from XML file in LINQ and C#
- Query with LINQ where Context matches multiple parameters from a List of Objects
- Prioritizing fields when matching multiple fields with linq
- Joining and grouping multiple tables with LINQ when using a linking table
- How to get identity from multiple objects when adding those with Entity Framework?
- How can I use drop down list value (String) to filter linq results?
- join multiple tables using LINQ
- Why an error occurs after I modified my model class?
- Lambda expression question
- LINQ Query takes too long
- Assign COUNT() to model field when projecting into a Model
- LINQ distinct items by Date part only from DateTime field in Select clause
- How to use two substring() method in join condition in linq
- Linq to Xml, keep XDocument loaded?
- OrderBy("it." + sort) -- Hard coding in LINQ to Entity framework?
- update with LINQ, and in operator select
- How to use group by in LINQ Asp c#
- How to get elements without child elements?
- How to Check Whether an Array (or List) Contains Another an Array (List) Using LINQ
- Read the lines & create lists based on matching values from specific start position to till specific end
- How to cast my Linq query to the expected Web API return type
- conditional linq query behavior
- Fetching data from 50+ tables using Linq-to-Nhibernate
- C# Linq search inside object linked property
- Why is LINQ's default ID(Primary Key) ReadOnly=False?