Go Down

Topic: Extracting substring of variable length (Read 3668 times) previous topic - next topic


Code: [Select]
printf("%s\n", s); // prints 8613920001234
Where the heck did s come from?
The art of getting good answers lies in asking good questions.


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


Rob Gray aka the GRAYnomad www.robgray.com


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.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) {
    finalstring = readString.substring(21, 35);


Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131