Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi...
i have read sms using at commands. now i need to show them. i need a regular expression to match the sms.
my at command response for cmgr is

AT+CMGR=2 +CMGR:"REC READ","+919529081800", "0", "0",,"11/02/21,20:06:38+22"

This is a test message,0,12,0

OK


pls give me regular expression to match the response in order to extract only the text......

thanks in advance
Posted

1 solution

If your response is exactly as shown, then you don't need a regex: use string.Split instead:
C#
string response = "AT+CMGR=2 +CMGR:\"REC READ\",\"+919529081800\", \"0\", \"0\",,\"11/02/21,20:06:38+22\"\n" +
                  "\n" +
                  "This is a test message,0,12,0\n" +
                  "\n" +
                  "OK";
            string[] lines = response.Split('\n');

Ignore the first and last lines, and you have the text.
 
Share this answer
 
Comments
surajking123 5-Mar-11 6:01am    
thanks Griff..

but i need to do this for each and every message. if i use regex then i can list the whole inbox..
Toli Cuturicu 5-Mar-11 14:05pm    
Use it for each and every message!
What works for one will work for all!
Be brave!
OriginalGriff 5-Mar-11 14:54pm    
To add to Toli's comment:
Using this on each message individually also prevents problems that make teh regex even more complicated. What happens to the regex if I send you an SMS saying:
OK
AT+7HOURS WE DEPART.
If you process them all together, the "OK" on it's own line looks like the end of a message, and the "AT+" looks like it could be the start of another...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900