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 Query
- 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 does linq actually execute the code to retrieve data from the data source?
- Linq select strings from list when condition is met and save the index
- Retrieve the node values from XML file in LINQ and C#
- How to retrieve multiple rows from a stored procedure with Linq to SQL?
- Get the max date from linq with mutiple joins and with multiple select fields
- I need to save the XML file using linq with xml code in C#
- C# Linq "Entity with the same key '0' already added." when inserting multiple rows
- C# Linq XML get text from multiple elements with the same name
- 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
- Left join on two Lists and maintain one property from the right with Linq
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Generating the Shortest Regex Dynamically from a source List of Strings
- How to get the latest date inserted from the table with Linq to entities
- How do I use Linq ToDictionary to return a dictionary with multiple values in the dictionary items?
- Does this LINQ code perform multiple lookups on the original data?
- When to prefer joins expressed with SelectMany() over joins expressed with the join keyword in Linq
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- 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
- Retrieve records from the database matching multiple values of a list
- Joining two tables with LINQ while also returning null records from the second table
- Return Count from Netflix oData Service When the LINQ Count() Method Doesn't Work
- Count the number of children in my JSON file using JSON.NET with LINQ
- How to create a list from filtering 2 lists with linq to object
- Removing a single item from an enumerable source when the items are equal
More Query from same tag
- Linq2Entities Equivalent Query for Parent/Child Relationship, With All Parents and Children, Filtering/Ordering Children
- Apply where condition on the child table in Linq to SQL
- C# Linq Convert Object Property to Array
- Entity Framework Insert In Code
- Linq MaxBy with all elements?
- Static ObservableCollection Event is not firing
- testing for no return from LINQ
- sum of item prices that have the same item id
- Run an IQueryable with Entity Framework
- Linq: How to make an object from linq result
- Linq sorting of entity by custom property via reflection
- Query children and its children until there are no children simplified
- Linq outer join possible issue
- LINQ query with variable in where clause
- c# Remove nodes from xml file irrespective of hierarchy
- How to add list data to multi sub class list data?
- Good way to connect parent table/entity with child table/entities?
- c#: Using Linq to get a IEnumerable collection of XML Nodes to Traverse
- WPF Combobox databinding to a L2S table
- Use LINQ to compare two lists, and produce a third one with results from one OR the other
- Using LINQ to find a common prefix?
- using LinQ without Lambda expressions to define condition on a List type property
- Linq Query : Cannot convert type IEnumerable<string> to string changing .ToString() to (string)
- Can second parameter of Expression.Property be made dynamic?
- Linq query to check substring between a list and string
- Add numbers part of a string using LINQ
- Return only nessesary data in Linq request
- Formatting Dates in LINQ query when using GroupBy
- When is data loaded into app server's memory?
- Return distinct list of object array where number of array items is non-specific