1

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
Michel Keijzers
13k7 gold badges41 silver badges58 bronze badges
asked Jan 10, 2018 at 15:45
1
  • 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 */ Commented Jan 10, 2018 at 16:13

1 Answer 1

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.

answered Jan 10, 2018 at 15:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.