我将收到的消息添加到通过串行端口从 GSM 调制解调器读取的文本文件中。稍后我使用正则表达式解析这些消息并将它们显示在列表视图中。接收单行消息并显示它们都很好,但是当我收到多行消息时,我无法阅读它们。我想我应该改变我用来解析的正则表达式。建议请..
public ShortMessageCollection ParseMessages(string input)
{
ShortMessageCollection messages = new ShortMessageCollection();
Regex r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""\r\n(.+)\r\n");
Match m = r.Match(input);
while (m.Success)
{
ShortMessage msg = new ShortMessage();
msg.Index = m.Groups[1].Value;
msg.Status = m.Groups[2].Value;
msg.Sender = m.Groups[3].Value;
msg.Alphabet = m.Groups[4].Value;
msg.Sent = m.Groups[5].Value;
msg.Message = m.Groups[6].Value;
messages.Add(msg);
m = m.NextMatch();
}
return messages;
}
input
是一个字符串变量,它包含从文件中读取的数据。单行消息input
是这样的:
+CMGL: 1,\"REC UNREAD\",\"IA-612345\",\"\",\"2012/08/14 12:56:46+22\"\r\nRecharge with RC45 & get 100 local minutes valid for 15days.For details call 53640 (Toll Free)\r\n\r\n
多行消息是这样的:
+CMGL: 1,\"REC READ\",\"+919909965834\",\"\",\"2012/08/17 09:55:29+22\"\r\nHai helo\nthis is a\ntest mesg\r\n\r\nOK\r\n
如何正确完整地阅读多行消息中的消息部分?