Go Down

Topic: Extracting substring of variable length (Read 1 time) previous topic - next topic

PaulS

Code: [Select]
printf("%s\n", s); // prints 8613920001234
Where the heck did s come from?

Graynomad

Oops, my bad. Tried to clean the snippet up and only did half the job.

Fixed.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

zoomkat

Simple extraction of the phone number of the below string (copy string, paste in the serial monitor and send to the arduino to test).

+CMGR: "REC UNREAD","+8613920001234","","12/12/13,15:08:55+50"

Code: [Select]
// zoomkat 7-30-11 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

String readString;
String finalstring;

void setup() {
  Serial.begin(9600);
  Serial.println("serial test 0021"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(2);  //delay to allow byte to arrive in input buffer
    char c = Serial.read();
    readString += c;
  }

  if (readString.length() >0) {
    Serial.println(readString);
    finalstring = readString.substring(21, 35);
   Serial.println(finalstring);

    readString="";
    finalstring="";
  }
}

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up