Pages: [1]   Go Down
Author Topic: funzione split() in arduino  (Read 359 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

salve a tutti!! esiste una funzione split per le stringhe integrata nelle librerie di arduino??
grazie
Logged

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

Milano, Italy
Offline Offline
Faraday Member
**
Karma: 11
Posts: 3091
Sideralis Arduino!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

grazie, la proverò presto
Logged

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

Pages: [1]   Go Up
Jump to: