Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将2个集合匹配到1个列表_C#_Regex - Fatal编程技术网

C# 将2个集合匹配到1个列表

C# 将2个集合匹配到1个列表,c#,regex,C#,Regex,嗨,伙计们,我有两个火柴系列: MatchCollection users_ids = Regex.Matches(result, @"url"":""(.*?)"""); MatchCollection users_names = Regex.Matches(result, @"fullname"":""(.*?)"""); 两个集合的数学数为 我需要将所有匹配项加入到一个列表中。Smth是这样的: foreach (Match match in users_

嗨,伙计们,我有两个火柴系列:

MatchCollection users_ids = Regex.Matches(result, @"url"":""(.*?)""");
MatchCollection users_names = Regex.Matches(result, @"fullname"":""(.*?)""");
两个集合的数学数为

我需要将所有匹配项加入到一个列表中。Smth是这样的:

                foreach (Match match in users_ids)
                {
                   string id = match.Groups[1].Value.ToString();
                  // string name = users_names(every match) .Groups[1].Value.ToString();
                   online_list.Add(id + "|" + name);
                }

有解决方案吗?=\

这看起来像是
Zip
的完美应用,它经过两次枚举,在每个项目的当前索引处提取项目,并使用给定函数将其映射到结果中:

var matches = users_ids.Cast<Match>()
    .Zip(users_names.Cast<Match>(),
    (id, name) => id.Groups[1].Value + "|" + name.Groups[1].Value);
var matches=users\u id.Cast()
.Zip(用户名称.Cast(),
(id,name)=>id.Groups[1].Value+“|”+name.Groups[1].Value);

这看起来像是
Zip
的完美应用,它经过两次枚举,在每个项的当前索引处获取项,并使用给定函数将它们映射到结果中:

var matches = users_ids.Cast<Match>()
    .Zip(users_names.Cast<Match>(),
    (id, name) => id.Groups[1].Value + "|" + name.Groups[1].Value);
var matches=users\u id.Cast()
.Zip(用户名称.Cast(),
(id,name)=>id.Groups[1].Value+“|”+name.Groups[1].Value);

这不起作用吗?问题是什么?你能提供一些示例输入吗?
result
包含什么?如何将第二个集合的元素添加到foreach循环中?Smtth-like-foreach(用户ID中的Match-Match和用户名称中的Match-match2)@Analcrab,答案是。(或者是一个
for
循环,但那就没那么有趣了。)这样不行吗?问题是什么?你能提供一些示例输入吗?
result
包含什么?如何将第二个集合的元素添加到foreach循环中?Smtth-like-foreach(用户ID中的Match-Match和用户名称中的Match-match2)@Analcrab,答案是。(或者为循环设置一个
,但那就没那么有趣了。)