How to conver string into array with float values

I have variable like this:

String stringData = "12.34|14.36|98.12|1.4|345.3";

and now I want to convert it to get:

float myData = {12.34, 14.36, 98.12, 1.4, 345.3};

How can I do this?

Did you try atof?
What went wrong?

I even don't know how split this string :frowning:

XnIcRaM:
I even don't know how split this string :frowning:

Please see reply #1

atof is for converting String to float then I need first split my string for smaler string which I can convert using atof

AWOL:
Please see reply #1

atof is for converting String to float then I need first split my string for smaler string which I can convert using atof, dunno how first answer can help me with split :confused:

atof is for converting String to float

No.

about atof I found something like this IBM Documentation
it says atof() — Convert Character String to Float
I really don't know how to split my string using atof

PS. sorry I don't understand strings or String in C, why its not that simple like php or javascript? :confused:

it says atof() -- Convert Character String to Float

You really have to be careful about those capitals

string != String

why its not that simple like php or javascript?

Have you ever considered the environments where those languages run?
Do those environments look like Arduinos?

XnIcRaM:
String stringData = "12.34|14.36|98.12|1.4|345.3";

Is that a | (what I've always called a pipe) or a small L between the numbers? Could that not be used to separate the numbers?

The function first discards as many whitespace characters (as in isspace) as necessary until the first non-whitespace character is found. Then, starting from this character, takes as many characters as possible that are valid following a syntax resembling that of floating point literals (see below), and interprets them as a numerical value.

I try to see what atof do:

void setup() {
  String stringData = "12.34|14.36|98.12|1.4|345.3";
  Serial.println(atof(stringData));
}

but get error:

cannot convert 'String' to 'const char*' for argument '1' to 'double atof(const char*)'

Great - so don't use Strings

thanks for help :confused:

Your thread got me researching. Maybe have a look at what strtok_r() might be able to do for your problem.

Here's a thread with a problem very similar to yours.

Are you understanding Awol?

A String (capital S) and a string (small s) are 2 completely different things. String (capital S) is a bad word in the Land of Arduino. Don't use it. Use string.

DangerToMyself:
Are you understanding Awol?

A String (capital S) and a string (small s) are 2 completely different things. String (capital S) is a bad word in the Land of Arduino. Don't use it. Use string.

I don't understand Awol.
I know that there is big diffrence beetwen String and string (but I don't understand it :/) In my example I use String because I don know how to don't use it :confused:

I got this String from HTTP response from my PHP script

http.begin("http://my.webserver/script.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.POST("id=" + String("1"));
String dataString = http.getString();

In this response I get few float value separated by sign |. I need store this values in float array

Is it possible to not use String here?

Is it possible to not use String here?

Yes, but since you are so far down that rabbit hole anyway, look at the damned reference page for String. There is an indexOf() method. Don't you suppose that you could use that to find the pipe sumbols? There is a substring() method, to make a String out of a String, knowing what parts you want to extract (that would be the parts between the pipe symbols). There is a toFloat() function, which does something that might prove useful.

RTFM.