Hi all,
I want to do a search of a list of strings, non cap sensitive.
Have tried .Contains and ==
Is there a method to do this, or would I have to convert the entire list of strings to noncaps, then search?
Cheers!
Hi all,
I want to do a search of a list of strings, non cap sensitive.
Have tried .Contains and ==
Is there a method to do this, or would I have to convert the entire list of strings to noncaps, then search?
Cheers!
How about String.IndefOf with the StringComparison argument set? Alternatively, build a RegEx.
One way to do it.
var answer = list.FirstOrDefault(item => item.Equals("test", StringComparison.CurrentCultureIgnoreCase));
Assuming you use C# 3:
var all = new [] {"A", "a", "AB", "aB", "Ab". "Etc"};
var searchItem = "A";
var found = all.Where (x => string.Compare(x, searchItem, StringComparison.InvariantCultureIgnoreCase) == 0);
foreach(var foundItem in found)
Console.WriteLine(foundItem);
You can simply use String.ToUpper() to compare as non sensitive. (Just uppercase both strings you're comparing).
Or there are more advanced string comparison helpers in the .net lib: