我需要从字符串中提取票证号码。字符串示例:
string body = "Hello, world welcome. [TKNM-1234] Blah blah [HelpCode-5] Blah blah";
Run Code Online (Sandbox Code Playgroud)
我只需1234要从该字符串中提取。做这个的最好方式是什么。我以前尝试过:
int from = body.IndexOf("[TKNM-") + "[TKNM-".Length;
int to = body.LastIndexOf("]");
ticketNumber = body.Substring(from, to - from);
Run Code Online (Sandbox Code Playgroud)
但这是由于TKNM之后的其他括号而引起的问题。一切都在C#中。
| 归档时间: |
|
| 查看次数: |
38 次 |
| 最近记录: |