user1043500
user1043500

Reputation: 37

Extracting text from SMS message in Python

This is an SMS message which I obtained using AT commands from mobile:

+CMGL: 24,"REC READ","DD-655501",,"11/11/10,17:10:26+22"
hey is it working "BBC news channel" pack @ Rs.10, Dial *234*7514#

Now I need to extract only the text message from it. I have tried a few approaches but something always gets missed. I am using Python. Any good suggestion?

Upvotes: 0

Views: 1365

Answers (1)

Mark Byers
Mark Byers

Reputation: 839154

The format of the response is:

+CMGL: index,message_status,address,[address_text],[service_center_time_stamp][,address_type,sms_message_body_length]
sms_message_body

(source)

You want all the text apart from the first line.

message_body = smsText[smsText.index('\r\n') + 2:]

Upvotes: 1

Related Questions