Print the string if substring is found

Hello All!!
I just received my Arduino Uno and want to do the following:

  1. I'm receiving serial data into Arduino as text.
  2. Have substring to look for a word within a string.
  3. Print only complete lines of serial data received if the word from substring exists.

I found a sample substring sketch and tried to modify, but with no luck :frowning: Any and all help is greatly appreciated.

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

void loop() {
while(Serial.available()>0){

String stringOne = Serial.readString();
if (stringOne.substring(2, 17) == "bob") { //want to see if string contains "bob"
Serial.println(stringOne); //print complete string if true
}
}
}

Forget that you ever heard about String (with capital S). Read [utl=http://forum.arduino.cc/index.php?topic=396450]serial input basics[/url] and apply the basics in there.

You can check if consecutive characters form the word bob, or use strstr() to check if the complete message contains the word bob.

Print all lines with 'bob'.

char pattern[] = "bob";

void setup() {
  Serial.begin(115200);
  Serial.print(F("Looking for '"));
  Serial.print(pattern);
  Serial.println(F("'"));
}

void loop() {
  byte inChar;
  bool doCheck = false;
  const byte lineBufferSize = 65;
  static char sCBuffer[lineBufferSize];
  static byte buffIndex = 0;

  while (Serial.available()) {
    inChar = Serial.read();
    if (inChar == 10) {
      continue;
    } else if (inChar == 13) {
      doCheck = buffIndex;
    } else {
      if ((buffIndex == 0) && isWhitespace(inChar)) {
        continue;
      }
      sCBuffer[buffIndex++] = inChar;
      doCheck = (buffIndex == (lineBufferSize - 1));
    }
    if (doCheck) {
      sCBuffer[buffIndex] = 0;
      if (strstr(sCBuffer, pattern)) {
        Serial.println(sCBuffer);
      }
      buffIndex = 0;
    }
  }
}

I'm trying to use pin 10 to receive my serial data into the Ardunio. Then only send lines that contain "Bob" in them to excel using PLX-DAQ. So anytime pin 10 on the Arduino sees serial data, process the data and look for "Bob", then send the entire line containing "Bob'" to excel and when if a new line of data containing "Bob" comes in, update to the next row in excel. Here's what I have but not working.... I appreciate any suggestions...thank you in advance.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10);  //rx on pin 10

char pattern[] = "Bob";
char row = 0;

void setup() {
  Serial.begin(38400);
  //Serial.print(F("Looking for '"));
  //Serial.print(pattern);
  //Serial.println(F("'"));



mySerial.begin(38400); // the bigger number the better
//pinMode(rxPin, INPUT)
Serial.println("CLEARDATA"); //clears up any data left from previous projects

Serial.println("LABEL,Acolumn,"); //always write LABEL, so excel knows the next things will be the names of the columns (instead of Acolumn you could write Time for instance)


}

void loop() {
  byte inChar;
  bool doCheck = false;
  const byte lineBufferSize = 65;
  static char sCBuffer[lineBufferSize];
  static byte buffIndex = 0;

while (mySerial.available() > 0) {
    inChar = mySerial.read();
    if (inChar == 10) {
      continue;
    } else if (inChar == 13) {
      doCheck = buffIndex;
    } else {
      if ((buffIndex == 0) && isWhitespace(inChar)) {
        continue;
      }
      sCBuffer[buffIndex++] = inChar;{
      doCheck = (buffIndex == (lineBufferSize - 1));
    }
    if (doCheck) {
      sCBuffer[buffIndex] = 0;
      if (strstr(sCBuffer, pattern)) 
        Serial.print("DATA,sCBuffer");{
      
      buffIndex = 0;

Serial.print("DATA,sCBuffer,"); //writes the time in the first column A and the time since the measurements started in column B
row++;
  row=0;
  
Serial.println("ROW,SET,2");

//Serial.println(...); //be sure to add println to the last command so it knows to go into the next row on the second run

    delay(100); //add a delay
}
}    
}
}
}