Rafael Herscovici
Rafael Herscovici

Reputation: 17094

indexof a string from a list in another list

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.

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

Answers (2)

BrokenGlass
BrokenGlass

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

Bala R
Bala R

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

Related Questions