Pages: 1 [2]   Go Down
Author Topic: Extracting substring of variable length  (Read 1567 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 652
Posts: 50865
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Fixed.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Tesla Member
***
Karma: 147
Posts: 9741
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
// 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="";
  }
}

Logged

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

Pages: 1 [2]   Go Up
Jump to: