Search specific string and change the type into int

Hi all,

I have some problem of searching specific string.My arduino will get a lot of stings and only the string with 'signal (0,0)' is useful, such as, 'signal (0,0) 12.546 ' or 'signal (0,0) 11.343'. Therefore, my arduino should search the string with 'signal(0,0)' and keep this kind of strings. However, I don't konw what kind of code that can achieve this function.

Please give me some help, big thanks !!!

Serial test code that looks for a specific character string inside a larger character string sent from the serial monitor.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

//A very simple example of sending a string of characters 
//from the serial monitor, capturing the individual 
//characters into a String, then evaluating the contents 
//of the String to possibly perform an action (on/off board LED).

int ledPin = 13;
String readString;

void setup() {
  pinMode(ledPin, OUTPUT); 
  Serial.println("serial on/off test 0021"); // so I can keep track

void loop() {

  while (Serial.available()) {
    char c =;
    readString += c; 

  if (readString.length() >0) {

    if(readString.indexOf("on") >=0)
      digitalWrite(ledPin, HIGH);
      Serial.println("LED ON");

    if(readString.indexOf("off") >=0)
      digitalWrite(ledPin, LOW);
      Serial.println("LED OFF");


How does the data arrive? Is it a really long string with one "signal (0,0) 12.546" buried within the long string, or is it a series of short string, but they might be "signal (1,1) 12.546" in which case it is discarded? While the String class is easy to use, it chews up more memory than is likely needed to get the job done. If, for example, the string arrives in 100 byte chunks that's terminated with a newline character ('\n'), then:

void setup() {
  // put your setup code here, to run once:

// Test string: This is a test with a target string buried in it signal (0,0) 12.345 and more junk.

void loop() {
  char input[101];  // room for the null
  char *ptr;
  int charsRead;

  if (Serial.available() > 0) {
    charsRead = Serial.readBytesUntil('\n', input, 100);
    input[charsRead] = '\0';     // It's now a C string

    ptr = strstr(input, "signal (0,0)");
    if (ptr) {
    } else {
      Serial.println("No match");


With a little thought, you'll be able to figure out how to extract the numbers.

Hi econjack,

Thank you for your answering and it is really helpful.

The data is send from BCI2000 to Arduino via UDP and is it a series of short string. In our case, we just have “signal(0,0)” and other string such as “recording” of “target” which should be discarded.

My supposed step for processing the received data is :
1, search all string with “signal (0,0)” , and discard the other useless data
2, discard the “signal (0,0)” and keep the following numerical string which should be changed into int type.
3, I am not sure about the following step, because we need to analyze data first

about the how to extract the numbers, i will think about it.
A big thanks to you !!