Learn about, and use, a regular expression (see the
Regex[
^] class)
It looks like you're going to want a pattern like:
^Aligning the value (\S+) .* >(.+)<
The two "capture groups" of matching lines can be extracted to the output.
First create the
Regex
:
using System.Text.RegularExpressions;
private readonly static Regex Extractor = new Regex(@"^Aligning the value (\S+) .* >(.+)<", RegexOptions.Compiled);
This can be done once and "compiled" for efficiency.
Then process the lines:
foreach(string line in filetext)
{
Match m = Extractor.Match(line);
if (m.Success)
{
Console.Writeline("{0} {1}", m.Groups[1], m.Groups[2]);
}
}
(And,
yes, the indexing into
Groups
is one-based!)