I have a string containing 3 or 4 double numbers. what's the best way to extract them in an array of numbers?
-
1Please post the string. There are many ways how 3 or 4 double numbers can be contained in a string.Günter Zöchbauer– Günter Zöchbauer2018-08-25 15:58:33 +00:00Commented Aug 25, 2018 at 15:58
-
it might be like"Points (64.5464864, 34.668464)" I'm not just looking for a way for a special data. it will be so good if it was a more generic way;Moein Hosseini– Moein Hosseini2018-08-25 21:34:20 +00:00Commented Aug 25, 2018 at 21:34
Add a comment
|
1 Answer
First you have to find the numerals. You can use a RegExp pattern for that, say:
var doubleRE = RegExp(r"-?(?:\d*\.)?\d+(?:[eE][+-]?\d+)?");
Then you parse the resulting strings with double.parse. Something like:
var numbers = doubleRE.allMatches(input).map((m) => double.parse(m[0])).toList();