我有以下代码来从一个输入文件中提取特定的标记:
string sLine = File.ReadAllText(ituffFile);
Regex rxp = new Regex(@"2_tname_(?<token>\S+)", RegexOptions.Compiled);
MatchCollection rxpMatches = rxp.Matches(sLine);
现在我想把包含我要查找的元素的MatchCollection转换成HashSet。
如何最快地实现这个目标?
以下是最佳方法吗?
HashSet<string> vTnames = new HashSet<string>();
foreach (Match mtch in rxpMatches)
{
vTnames.Add(mtch.Groups["token"].Value);
}