Splitting incoming strings on serial port

Hi all :)

Total noob, first post on the forums.

I just got my shiny new UNO boards and I'm slowly learning the language. I have 2 boards connected by 2 xbee modules. One of them is sending sensor information through the serial port. The string for each sensor value is separated by "|".

Serial.print("|");
Serial.print(value[x]);

So the string that's sent over the port looks like this: 894|320|440|560

I can't seem to figure out how to split it up again and read one by one once it's received by the other board. In C# it's done by

 string[] recievedStrings = comport1.ReadLine().Split("|");
 int servopos = recievedStrings(1)

Any thoughts?

I can’t seem to figure out how to split it up again and read one by one once it’s received by the other board.

The data is received (read) character by character on the receiving end. Store the characters in an array. Stop reading and storing when you encounter a |. Convert the stored array to an integer, and resume reading.

That's what you get for using too much C#!! It's too easy on you. You will be storing your incoming string into a char array. and see if you hit a "|". Once you do, parse the value of the char array, clear it and do it again.

char msg[10];
int pointer=0;
while(Serial.available())
{
msg[pointer]=Serial.read();
if msg[pointer]=="|"
{
int temp=parse_number(pointer-1);
do_something_with_number(temp);
pointer=0;
}
else pointer++;
}

Some simple code you can try.

//zoomkat 9-9-10 simple delimited ',' string parce 
//from serial port input (via serial monitor)
//and print result out serial port
// CR/LF could also be a delimiter

String readString;

void setup() {
    Serial.begin(9600);
        }

void loop() {

        //expect a string like wer,qwe rty,123 456,hyre kjhg,
        //or like hello world,who are you?,bye!,
        while (Serial.available()) {
        delay(1);  //small delay to allow input buffer to fill
      if (Serial.available() >0) {
        char c = Serial.read();  //gets one byte from serial buffer
        if (c == ',') {break;}  //breaks out of capture loop to print readstring
        readString += c; } //makes the string readString
        }
      
      if (readString.length() >0) {
      Serial.println(readString); //prints string to serial port out
      
      readString=""; //clears variable for new input
      }
   }