我知道 MatchCollection
中始终只有一个元素:
Regex reg = new Regex("1234");
MatchCollection matches = reg.Matches("fjasij 1234 gdsgds");
Console.WriteLine(matches.Count);
string s = ?;
如何在没有foreach
循环的情况下将这个元素赋值给变量string s
?
最佳答案
为什么要使用 MatchCollection
呢?只需获取一个 Match
:
var match = reg.Match("fjasij 1234 gdsgds");
关于c# - 如何从 MatchCollection 中获取唯一元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21126569/