I want to read a SMS message , find it's length and do some "substring();" operation on received SMS. My last two(2) statements do not work . How can I get correct answers? What are correct codes ?
#include <SoftwareSerial.h>
#include <string.h>
#include <ctype.h>
SoftwareSerial mySerial(2,3);
String TelephoneNumberText="";
void setup()
{
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
mySerial.begin(9600);
Serial.begin(9600);
delay(100);
mySerial.println("AT+CMGF=1\r"); //Sets the GSM Module in Text Mode
delay(500);
}
void loop()
{
while(mySerial.available())
{
char s;
s = mySerial.read();
TelephoneNumberText = TelephoneNumberText + s;
}
Serial.println(TelephoneNumberText); // this statement works
Serial.println(TelephoneNumberText.length()); // this statement dose not works
Serial.println(TelephoneNumberText.substring(0,3));// this statement dose not works
} // end loop
-
Serial.println(TelephoneNumberText); // this statement works Serial.println(TelephoneNumberText.length()); // this statement dose not works Serial.println(TelephoneNumberText.substring(0,3));// this statement dose not works /* please tell me correct codes for above two(2) statements */muditha– muditha2018年01月10日 16:13:50 +00:00Commented Jan 10, 2018 at 16:13
1 Answer 1
Are you sure a string like this can be used?
Better anyway to not each time let a dynamic string be created, but use a fixed string e.g.
char TelephoneNumberText[16];
Set the length of the max number, and change other string functions accordingly.
Explore related questions
See similar questions with these tags.