Go Down

Topic: funzione split() in arduino (Read 423 times) previous topic - next topic

salve a tutti!! esiste una funzione split per le stringhe integrata nelle librerie di arduino??
grazie
Freedomotic Open IoT Framework
http://www.freedomotic.com
We need your help. Please contact us for contributing

Federico

Purtroppo no. Sul forum avevo trovato questa soluzione

Quote

Re: whatever delimited strings / split
Reply #3 - 08.11.2008 at 03:25:32 
Assuming you have managed to get a string buffer full of delimited data, it's pretty easy to iterate through it using the standard library function strtok_r().  For example this little sketch:

#include <string.h>

char sz[] = "Here; is some; sample;100;data;1.414;1020";
void setup()
{
char *p = sz;
char *str;
Serial.begin(9600);
while ((str = strtok_r(p, ";", &p)) != NULL) // delimiter is the semicolon
   Serial.println(str);
}

void loop(){}

generates this output:

Here
is some
sample
100
data
1.414
1020

That said, Arduino doesn't have any facilty for directly reading a string into a buffer.  As AlphaBeta says, you get serial characters, well, serially.  But it's not too hard to write your own GetString() function.

Mikal
Federico - Sideralis
Arduino &C: http://www.sideralis.org
Foto: http://blackman.amicofigo.com

Freedomotic Open IoT Framework
http://www.freedomotic.com
We need your help. Please contact us for contributing

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy