3

I have a string containing 3 or 4 double numbers. what's the best way to extract them in an array of numbers?

2
  • 1
    Please post the string. There are many ways how 3 or 4 double numbers can be contained in a string. Commented 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; Commented Aug 25, 2018 at 21:34

1 Answer 1

6

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.