I have a a string containing this text…
BEGIN Fin Bal -461.000 Day 4 END
BEGIN Fin Bal 88861.000 Day 2 END
BEGIN Fin Bal 456461.000 Day 1 END
BEGIN Fin Bal -44561.000 Day 0 END
I need to extract the value
-461.000
Including if its negative or not.
I have been using this…
static string ExtractNumbers(string expr)
{
//removes all text from string
return string.Join(null, System.Text.RegularExpressions
.Regex.Split(expr, "[^\\d]"));
}
Problem is this removes the negative symbol and also keeps the 4 from the day value.
Is there any way to get the numeric value after the word Bal efficiently? Excluding any text after the wanted value?
Thanks, Paul.
For a LINQ solution which grabs the first number: