Extracting list of floats from string C#

Hey guys!!

I have just run into something I haven’t managed to get my head around. I have a string which contains a varying amount of floats which are varying lengths.
I need to extract each float and place them in a List.

Here’s an example:

This is the string:

[0.00442398712038994, 0.640771448612213, 0.830118358135223, 1.1674565076828, 1.52580320835114, 1.57927715778351]

I want it to be split up into as many number of floats as there are numbers here.

I only need help with splitting. I know how to put it in a list.
The only reason I’m having trouble with this is the fact that there isn’t really a consistent separation that I can see.

Usually I would use:

string[] splitter = {"\", \""};

string[] namesArray = input.Substring(2, input.Length-4).Split(splitter, System.StringSplitOptions.None);


foreach (var name in namesArray) {

string nameInput = nameStringJSON;

string name = nameInput.Substring(55, nameInput.Length-57);

print("name");

}

Maybe there is some way of extracting floats and placing them in a list?

Try this:

using System.Linq;
using System.Collections.Generic;

var myList = inputTextString.Split(',').Select(Convert.ToSingle).ToList();

or

var myArray = inputTextString.Split(',').Select(Convert.ToSingle).ToArray();