RedFilter's answer is nice and compact, but LINQ is not a very efficient method here: it will go through "BEGIN", "Fin" and "Bal" before it gets to your number. Also note that the RedFilter method uses both TryParse and Parse for the same operation (I understand that this is a side effect of LINQ, but this is an extra overhead). If this is the fourth item on your line, you can try something similar to:
string val = "BEGIN Fin Bal -461.000 Day 4 END"; float FinBal; bool success = float.TryParse(val.Split(' ')[3], NumberStyles.Float, new NumberFormatInfo(), out FinBal); if (success) { Console.WriteLine( "{0:F3}",FinBal); }
source share