簡體   English   中英

從模式中提取文本

[英]Extract text from pattern

我有一個 sim 800 模塊。 我閱讀了存儲在 SIM 卡中的所有消息。 返回下面的響應。 我想要單獨的電話號碼、時間和回復文本。 但我不知道怎么做


+CMGL: 1,"REC READ","number","","2019/10/11 17:09:44+14"
this is text

+CMGL: 2,"REC READ","989149161278","","2019/10/11 17:38:18+14"
this is text

+CMGL: 3,"REC READ","989149161278","","2019/10/11 17:55:03+14"
this is text

+CMGL: 4,"REC READ","989149161278","","2019/10/11 17:57:09+14"
this is text

+CMGL: 5,"REC READ","989149161278","","2019/10/11 18:14:22+14"
this is text

+CMGL: 13,"REC READ","989149161278","","2019/10/11 19:04:40+14"
this is text

+CMGL: 14,"REC READ","989149161278","","2019/10/11 19:07:12+14"
this is text

+CMGL: 15,"REC READ","989149161278","","2019/10/11 19:08:23+14"
this is text

+CMGL: 16,"REC READ","989149161278","","2019/10/11 19:21:17+14"
this is text

+CMGL: 17,"REC READ","989149161278","","2019/10/11 19:30:31+14"
this is text

+CMGL: 18,"REC READ","989149161278","","2019/10/11 20:15:49+14"
this is text

+CMGL: 19,"REC READ","989149161278","","2019/10/11 20:41:36+14"
this is text

+CMGL: 20,"REC READ","number","","2019/10/11 20:41:41+14"
this is text

OK

這可能不是最好的方法,但考慮到您的響應結構將始終保持不變,請考慮:

\+CMGL:\s\d+\,\"REC\sREAD\",\"(?<phone>.+)\",\"(?:.+)?\",\"(?<time>.+)\"|^(?<message>.+)$

正則表達式演示

本質上,捕獲整個字符串並通過組提取必要的信息。 您可以通過組名訪問各個組(參見右側的鏈接)。

您應該對此進行調查以解決您的問題。 https://www.tutorialspoint.com/csharp/csharp_regular_expressions.htm

或者,您也可以使用字符串拆分方法來划分逗號之間的內容。 https://www.geeksforgeeks.org/string-split-method-in-c-sharp-with-examples/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM