Skip to main content
deleted 1 character in body; edited tags; edited title
Source Link

Splice Slice string at “:”

I need to spliceslice a string (eg- 4:288:18464:288:4) at ":" into an array({4, 288, 18464, 288, 4}) I used the following code, but its giving only '4' in the serial monitor when "4:288:18464:288:4," is given to arduino.

void displayString(char* s)
{
  char* text = strtok(s,":");

  while(text != NULL){
  text = strtok(NULL,":");}
}

void loop()
{
  if(Serial.available() > 0)
    {
        str = Serial.readStringUntil(',');
        str.toCharArray(text,99);
    }
  displayString(text);
Serial.println(text);
}

Splice string at “:”

I need to splice a string (eg- 4:288:18464:288:4) at ":" into an array({4, 288, 18464, 288, 4}) I used the following code, but its giving only '4' in the serial monitor when "4:288:18464:288:4," is given to arduino.

void displayString(char* s)
{
  char* text = strtok(s,":");

  while(text != NULL){
  text = strtok(NULL,":");}
}

void loop()
{
  if(Serial.available() > 0)
    {
        str = Serial.readStringUntil(',');
        str.toCharArray(text,99);
    }
  displayString(text);
Serial.println(text);
}

Slice string at “:”

I need to slice a string (eg- 4:288:18464:288:4) at ":" into an array({4, 288, 18464, 288, 4}) I used the following code, but its giving only '4' in the serial monitor when "4:288:18464:288:4," is given to arduino.

void displayString(char* s)
{
  char* text = strtok(s,":");

  while(text != NULL){
  text = strtok(NULL,":");}
}

void loop()
{
  if(Serial.available() > 0)
    {
        str = Serial.readStringUntil(',');
        str.toCharArray(text,99);
    }
  displayString(text);
Serial.println(text);
}
Source Link
user3826856
  • 83
  • 1
  • 2
  • 4

Splice string at “:”

I need to splice a string (eg- 4:288:18464:288:4) at ":" into an array({4, 288, 18464, 288, 4}) I used the following code, but its giving only '4' in the serial monitor when "4:288:18464:288:4," is given to arduino.

void displayString(char* s)
{
  char* text = strtok(s,":");

  while(text != NULL){
  text = strtok(NULL,":");}
}

void loop()
{
  if(Serial.available() > 0)
    {
        str = Serial.readStringUntil(',');
        str.toCharArray(text,99);
    }
  displayString(text);
Serial.println(text);
}