Reputation: 17094
i have the following code:
foreach (var str in usedCSS)
{
if (CSS.Contains(str))
Response.Write(str);
else
Response.Write("Could not find: " + x + "<br />");
}
which dosent do exactly what i need, and i cant figure out what to do.
usedCSS
is a List<string>
CSS
is also a List<string>
the diffrence between them is that usedCSS
contains only the css style name e.g: .CssStyle
and CSS
Contains the full style e.g: .CssStyle {font-weight:bold)
what i want is to print out all the actual CSS code that is in usedCSS
.
i know i should use IndexOf
, but cant figure out how to.
I ask for your kind help.
Upvotes: 1
Views: 149
Reputation: 160852
How about:
foreach (var str in usedCSS)
{
if (CSS.Any( x=> x.StartsWith(str))
Response.Write(str);
else
Response.Write("Could not find: " + x + "<br />");
}
Upvotes: 0
Reputation: 108937
foreach (var str in usedCSS)
{
if (CSS.Any(c => c.Contains(str)))
Response.Write(str);
else
Response.Write("Could not find: " + x + "<br />");
}
alternatively, you could also use c.StartsWith(str)
i think.
Upvotes: 2