Help on parsing incoming data

Hi all,

I have an array of char i.e.: {2-1-0-BB-1-3-10-A-4-3-10-BB-0-3-A} ...

I would like to put into a new array only the data between the BB.....BB, so the saved array wil be only:

BB-1-3-10-A-4-3-10-BB

Don't know how to do it :fearful:

Don't know how to do it

Posting code is NOT rocket science. The stickies at the top of the forum - the ones that you were supposed to read BEFORE posting - detail how.

Go read them now.

go through the array, drop anything before the first BB, record until you reach the second BB, drop the rest.

You'll need to assemble a group of string functions to do this. Something like: search the source for a start delimiter; note that position; search for end delimiter; note position, and so on.

You may get some ideas by searching the forum for arduino substring char array.

This shows how to start it, but you need to generalize it so you can write a function that takes the search string (msg), the target string ("BB"), and copies it into a buffer parameter.

void setup() {

  char msg[] = "2-1-0-BB-1-3-10-A-4-3-10-BB-0-3-A";
  char buffer[20];
  char *start, *end;

  Serial.begin(9600);

  start = strstr(msg, "BB");        // Get a start address
  if (start) {                      // Match?
    end = strstr(start + 2, "BB");  // Yep...Find ending
    if (end) {                      // Yep...
      *(end + 2) = '\0';            // Chop off after end
      strcpy(buffer, start);        // Make a fresh copy...
    }
  }
  Serial.println(buffer);           // Show it
}

void loop() {
}

Have a look at the parse example in Serial Input Basics

...R

Hi Robin2,

your "Example 6 - Program to receive binary data" works great!! :slight_smile: :slight_smile: :slight_smile:

Thank you! :slight_smile: