谁能告诉我如何从这个输出中以简单的方式将以下信息提取到变量中。
输出:
AT+CMGL="ALL"
+CMGL: 0,"REC READ","+40728072005",,"12/06/29,13:04:26+12"
password,1,ON
我想从上面的输出中提取一些信息,如下所示:
msisdn="+40728072005"
passwd="password"
itemno="1"
command="ON"
--
string split = ",";
string[] substrings = Regex.Split(buff, split);
foreach (string match in substrings)
{
Console.WriteLine("'{0}'", match);
}
图片-> [1]:http: //i.stack.imgur.com/zl6Nj.png
有没有办法从一开始就排除不需要的输出?就像 grep -v,我对 C# 不是很熟悉。
到目前为止,我到了这一点:
string split = ",";
string split1 = "\"";
string split2 = "OK";
string[] substrings = Regex.Split(buff, split);
string[] substrings1 = Regex.Split(substrings[2], split1);
Console.WriteLine(substrings1[1]);
string[] substrings2 = Regex.Split(substrings[5], split1);
Console.WriteLine(substrings2[1]);
Console.WriteLine(substrings[6]);
string[] substrings3 = Regex.Split(substrings[7], split2);
Console.WriteLine(substrings3[0]);
不过,这是通过拆分字符串来完成的,因为我知道消息格式。