Reputation: 9900
I have the following:
var contents = new[]
{
"Theme Gallery", "Converted Forms", "Page Output Cache", "Master Page",
"(no title)", ".css", ".xml", ".wsp", ".jpg", ".png", ".master"
, ".000" , "Page Output Cache" , "_catalogs", "Style Library", "Cache Profiles"
};
string fileUrl = siteCollectionEntity.Url + '/' + item.Url;
And I'd like to write a statement that will prevent a loop from continuing if a URL contains any of the words found in contents. Apologies for the following poor syntax, but I think it will help to explain better what I'm trying to do... Basically something like the following:
if (fileUrl.Contains(contents)) continue;
Is something like this possible?
Upvotes: 0
Views: 72
Reputation: 1979
File URL is case insensitive. So I think you should do:
if (contents.Any(c => fileUrl.IndexOf(c, StringComparison.InvariantCultureIgnoreCase) != -1))
{
continue;
}
Upvotes: 0
Reputation: 166376
Try using Exists
Determines whether the specified array contains elements that match the conditions defined by the specified predicate.
Something like
if(Array.Exists(contents, s => fileUrl.Contains(s))) continue;
Upvotes: 1
Reputation: 254916
var contains = contents.Any(i => fileUrl.Contains(i));
Explanation:
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.any.aspx - there is a .Any()
method that LINQ
provides you.
It works as the following: it accepts a function reference (lambda in this case) which accepts one argument of the same type as your collection item (string
in your case, I called it i
) and must return a boolean. If there is true
returned for some element - the whole .Any()
returns true.
So basically it passes every item of the contents
array as i
into the fileUrl.Contains(i)
expression until one returns true
.
Upvotes: 5