Hello, I am working on my BLE project with arduino ide and I ran into a problem with splitting string. My arduino receives data - numbers from 0 to 200 with "," betweem them. For example - String data = 0,1,15,22,142. I want to send the data to another device, but I need to send them one by one. So i need to split the numbers by the "," and put them into some array. I know this wont be hard for you, so can anyone help me? I would really appreciate it. Thanks
Welcome to the forum
If you are using Strings rather than strings then a combination of the String functions indexOf() and substring() will allow you to do what you are asking
Thanks for your quick reply
int ReadDec(const char * & cp, char term) {
int t = 0;
while ((*cp) && (*cp != term) && (*cp >= '0') && (*cp <= '9')) {
t = (t * 10) + ((*cp++) - '0');
}
if ((*cp) && (*cp == term)) cp++;
return t;
}
Is that a pointer to a reference?
cp is a reference to a pointer to const char. It allows the calling function to share a pointer to the string and assign each returned value (ie delimited field) to a different variable. Also, the delimiter does not always have to be a comma, so it can parse a phone number into the respective parts, for an example.
From Serial? If o you could use "Serial.parseInt();" to get one number at a time.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.