Below I have a sample of a log file that I am working with:
5/21/2015 11:55:56 PM | Batch 6|386/767|50.33 %|CH2M-R|Processed NXRMN5...Checking refundable and non-refundable fares. Traditional Booking. Inside ticketing window. Minimum Savings Required: $131.00. Actual Savings: $257.18. Savings found: $257.18 (11.55 %). Savings were previously found.
Almost every line is like this, but some will say Savings not found. Below is the most important part of this sample:
Savings found: $257.18
I am trying to write a piece of code that will look through this log file, search through the whole file, and if savings were found, it will record that number into a variable, that way when I total it up, it will just fall into a variable.
The problem I am having right now is getting my code to display just that number. Below is what I have been working on thus far:
foreach (string line in gdsGroup)
{
Match m = Regex.Match(line, @"Savings\s+found:\s*\$(?<savings>\d+\.\d+)\s*\(\s*(?<percent>\d+\.\d+)\s*%");
if (m.Success)
{
decimal gdsNumberSavings = decimal.Parse(m.Groups["savings"].Value, CultureInfo.InvariantCulture);
decimal gdsNumberPercent = decimal.Parse(m.Groups["percent"].Value, CultureInfo.InvariantCulture);
string prefix = string.Empty;
if (gdsNumberPercent >= 30)
{
if (gdsNumberSavings >= 500)
prefix = "**";
else
prefix = "*";
}
Console.WriteLine(prefix + line + "\n");
Console.WriteLine(gdsNumberSavings);
}
}
}
The problem that is happening is that after the line that gives me what I have above, it prints out the of the savings for that line. So my question is, should I continue to try to go about a variable way, or do I need a regular expression to isolate that value, and if I need a regular expression what would the expression be?