Stripping out non-numeric characters in string
There are many ways, but this should do (don't know how it performs with really large strings though):
private static string GetNumbers(string input)
{
return new string(input.Where(c => char.IsDigit(c)).ToArray());
}
Feels like a good fit for a regular expression.
var s = "40,595 p.a.";
var stripped = Regex.Replace(s, "[^0-9]", "");
"[^0-9]"
can be replaced by @"\D"
but I like the readability of [^0-9]
.