float myAtof(string myString){ Predicate<char> testChar = c => c == '.' || c == '-' || c == '+' || char.IsDigit(c); myString = new string(myString.Trim().TakeWhile(testChar).ToArray()); if (myString.Length > 0) { float rvl; // accounts for bogus strings of valid chars, e.g. ".-": if (float.TryParse(myString, out rvl)) { return rvl; } } return 0;}