Setup
I have these three lists.
我有这三个清单。
List<List<string>> tokens = new List<string>();
List<string> token = new List<string>();
List<string> sets = new List<string();
One complete token
List that would be in the tokens
List.
一个完整的令牌列表,它将位于令牌列表中。
{"<card>"",
" <name>Domri Emblem</name>",
" <set picURL="http://magiccards.info/extras/token/Gatecrash/Domri-Rade-Emblem.jpg" picURLHq="" picURLSt="">GTC</set>",
" <color></color>",
" <manacost></manacost>",
" <type>Emblem</type>",
" <pt></pt>",
" <tablerow>0</tablerow>",
" <text></text>",
" <token>1</token>",
"</card>"}
The sets
list would look like this.
集合列表看起来像这样。
{"ARB", ..., "AVR", ..., "GTC", ..., "ZEN"}
I want to go through each token
in tokens
and remove each string in token
that contains any of the elements in set
.
我想遍历令牌中的每个令牌并删除包含集合中任何元素的令牌中的每个字符串。
Example
The tokens
list has a few token
elements. One token
(say token1) has an element like this.
标记列表具有一些标记元素。一个标记(比如token1)有一个这样的元素。
{..., " <set picURL="http://magiccards.info/extras/token/Gatecrash/Domri-Rade-Emblem.jpg" picURLHq="" picURLSt="">GTC</set>", ...}
Another token
(say token2) has these two elements.
另一个标记(比如token2)有这两个元素。
{..., " <set picURL="http://magiccards.info/extras/token/magic-2012/pentavite.jpg" picURLHq="" picURLSt="">M12</set>",
" <set picURL="http://magiccards.info/extras/token/player-rewards-2004/pentavite.jpg" picURLHq="" picURLSt="">MI</set>", ...}
Say the sets
list was modified to contain only {"ARB", "GTC", "M12"}
.
假设集合列表被修改为仅包含{“ARB”,“GTC”,“M12”}。
How would I go through each token
in tokens
and remove string elements that contain any of the string elements in sets
? So, after that process, token1 will not have that element above and token2 will only have the second presented element?
我如何遍历标记中的每个标记并删除包含集合中任何字符串元素的字符串元素?那么,在那个过程之后,token1上面没有那个元素,而token2只会有第二个呈现的元素?
What I Have Tried
This goes through each token
in tokens
and removes any element in token
that contains the string "GTC"
.
这将遍历令牌中的每个令牌,并删除包含字符串“GTC”的令牌中的任何元素。
foreach (var token in tokens)
{
token.RemoveAll(str => str.Contains("GTC"));
}
I looked through some other questions and found this but it doesn't work.
我查看了其他一些问题并发现了这个问题,但它不起作用。
foreach (var token in tokens)
{
token.RemoveAll(sets.Contains);
}
Thanks for the help.
谢谢您的帮助。
1 个解决方案
#1
5
foreach (var token in tokens)
{
token.RemoveAll(str => sets.Any(s => str.Contains(s)));
}
#1
5
foreach (var token in tokens)
{
token.RemoveAll(str => sets.Any(s => str.Contains(s)));
}