user29222: I am currently gathering info from a BLE device. I made a thread earlier where I successfully split a string consisting of 5 letters to their unique chars.
However from this BLE device i will also send some different information from time to time where I send 3 different values with a space after each one. So for example looking like this:
-0.1 0.51 0.07
So what I want to do now is to store this three numbers in different doubles and what I have done so far is this:
First i store the recieved message:
String recievedMessage;

recievedMessage += (char)BTLEserial.read();

Now I have to determine if the value sent is the 5 letters or if it is the numbers with a space between each value.
if (recievedMessage.length() > 5) //so if the recievedmessage is more than 5 words then it is the 3 values that is being sent.
{
char * charTheMessage = recievedMessage.c_str();
char *str;
str = strtok(charTheMessage, " ");

double one = str[0];
double two = str[1];
double three = str[2];

Serial.println (one);
Serial.println (two);
Serial.println (three);

}

if (recievedMessage.length() == 5)
{
 //http://arduino.stackexchange.com/questions/36227/how-can-i-split-a-string-into-multiple-parts/36237?noredirect=1#comment72313_36237
//Here I split the letters into 5 different values if the value sent is 5. 
}

But this values do not come out right when I print them in the serial monitor. I have also read that strtok is not reliable when data is sent fast so is strtok the right way to go you think?

user4143: You're almost there. Strtok returns the first token in the string only. You then have to convert that to a double yourself. You then call strtok again with NULL as the source string to get the next token. And so on.
I have written a good strtok example on here already. Look around, you may find it.

29222: <p>I am currently gathering info from a BLE device. I made a thread earlier where I successfully split a string consisting of 5 letters to their unique chars.</p>

<p>However from this BLE device i will also send some different information from time to time where I send 3 different values with a space after each one. So for example looking like this:</p>

<p><code>-0.1 0.51 0.07</code></p>

<p>So what I want to do now is to store this three numbers in different doubles and what I have done so far is this:</p>

<p>First i store the recieved message:</p>

<pre><code>String recievedMessage;

recievedMessage += (char)BTLEserial.read();
</code></pre>

<p>Now I have to determine if the value sent is the 5 letters or if it is the numbers with a space between each value.</p>

<pre><code>if (recievedMessage.length() &gt; 5) //so if the recievedmessage is more than 5 words then it is the 3 values that is being sent.
{
char * charTheMessage = recievedMessage.c_str();
char *str;
str = strtok(charTheMessage, " ");

double one = str[0];
double two = str[1];
double three = str[2];

Serial.println (one);
Serial.println (two);
Serial.println (three);

}

if (recievedMessage.length() == 5)
{
 //http://arduino.stackexchange.com/questions/36227/how-can-i-split-a-string-into-multiple-parts/36237?noredirect=1#comment72313_36237
//Here I split the letters into 5 different values if the value sent is 5. 
}
</code></pre>

<p>But this values do not come out right when I print them in the serial monitor. I have also read that strtok is not reliable when data is sent fast so is strtok the right way to go you think?</p>
 4143: <p>You're almost there. Strtok returns the <em>first</em> token in the string only. You then have to convert that to a double yourself. You then call strtok again with NULL as the source string to get the next token. And so on.</p>

<p>I have written a good strtok example on here already. Look around, you may find it.</p>
