Go Down

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

freedomotic

salve a tutti!! esiste una funzione split per le stringhe integrata nelle librerie di arduino??
grazie
Freedomotic Domotica Open Source
http://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

Freedomotic Domotica Open Source
http://freedomotic.com
We need your help. Please contact us for contributing

Go Up