I actually have strings formed like this one:
{ Desc = Marketcap, Val =
1,270.10 BTC
706,709.04 USD
508,040.00 EUR
4,381,184.55 CNY
425,238.14 GBP
627,638.19 CHF
785,601.09 CAD
72,442,058.40 JPY
787,357.97 AUD
7,732,676.06 ZAR
}
I'd need to parse out all the doubles in it, and I am actually stuck with that. How may I do that?
EDIT: I actually know how many numbers I am going to parse, that's fixed, like in that string (that's just the number that changes). I don't need the notation, neither (like BTC, USD, etc)
This uses a Regex to match blocks of text that start with a digit, contains a comma or period and ends with a digit. Seems to work for me just fine.
You can use
double
orDecimal
depending on what you need.If your data actually looks like this:
(Because what you have in your question is unclear.)
Then you could do this:
That gives you:
Also, you want to parse this as
Decimal
, notDouble
, asDecimal
is accurate for financial calculations andDouble
can lead to rounding errors.