Comments:
0) requires Linq, uses the 'Func Delegate syntax for economy.
1) fortunately, conversion to Double from all the other numeric Types will work: otherwise, this would be a mess to implement.
2) the code here shows examples of extracting converted, filtered, numbers based on a function you supply. left for you to write is taking the sets of filtered data and turning them back into a .dat file you save ... hint: use a StringBuilder
public static class SelectNumbers
{
private static char[] split1 = new char[] {'\r', '\n'};
public static double[] LinesToDouble(string data)
{
data = data.Trim();
string[] lines = data.Split(split1, StringSplitOptions.RemoveEmptyEntries);
var trimlines = lines
.Select(line => line.Trim());
return trimlines.Select(line => line.StringToDouble()).ToArray();
}
public static double StringToDouble(this string str)
{
double value;
if (double.TryParse(str, out value))
{
return value;
}
throw new InvalidCastException($"{str} ... is not a number");
}
}
usage example:
var ns = SelectNumbers.LinesToDouble(@"
1
2
5
3.999
-4
533
5
-6.456
");
double[] matchlta = GetMatchingValues(4.0, ns, (double d1, double d2) => d1 < d2);
double[] matcheqa = GetMatchingValues(5.0, ns, (double d1, double d2) => d1 == d2);
Feel free to ask questions.