(Sep 30, 2017 02:02 PM)Owl Wrote: I like Dead's suggestion. Something like:
Code
var skip = false;
foreach (var line in lines)
{
if (line == "[start]" || line == "[finish]")
skip = !skip;
else if (skip)
continue;
else
// proceed
}
You could also index the start and finish points and interest them into a standard for loop.
This is pretty much what I had in mind, but you might want to be careful about the adverse effect if having a potential duplicate starting or end tag somewhere in the data. If [start] is meant to only indicate the start of the
ignore phase, your logic would trigger an
unignore if a duplicate [start] tag was found when you may only want to start that
unignore flag when you see the [end] tag. Any assumptions past this however, becomes a fine line bordering on the premise of "uneducated guesswork" given the limited amount of details provided by OP, so I'll only add this as a mention for now.
As pseudocode this is a clear representation though.
Code
bool skip = false;
foreach (var line in lines)
{
if (line.Equals("[start]", StringComparison.Ordinal))
{
skip = true;
}
else if (line.Equals("[finish]", StringComparison.Ordinal))
{
skip = true;
}
else if (!skip)
{
// relevant data
}
}