[RESOLVED] Case insensitive search through list
Just a quick one - I've got a List(Of String) and want to check to see if it contains a specific string already. The problem is that I dont want this to be case sensitive and I cant seem to find any way of doing this with the built in Contains method - am I missing something obvious or do I have to just manually loop through the collection and use String.Compare ?
Cheers
Chris
Re: Case insensitive search through list
You could use the LINQ method. Its something like this :
Code:
list.Contains("WhateverYouLookFor", StringComparer.OrdinalIgnoreCase)
Re: Case insensitive search through list
Ah thanks thats exactly what I was looking for :) I knew it was just me being stupid...
though I think you might have meant extension method rather than LINQ method?
Re: Case insensitive search through list
Quote:
Originally Posted by
chris128
though I think you might have meant extension method rather than LINQ method?
Looks like it uses the linq namespace, see for yourself here, but I might be wrong on that, maybe its just an extension method :p .