I'm looking for a simple collection that will store a bunch of strings in a case insensitive way. I need at least a Contains()
and Remove()
method to see if a certain string is present and to remove that string.
I've tried List<string>
but that one is case sensitive. I need could use a case insensitive Dictionary<TKey, T>
, but that "feels" like a waste of space. Doing a ToLower()
on each string is a waste of performance.
Does anyone know what kind .Net collection I should use?
The string. Contains() method in C# is case sensitive. And there is not StringComparison parameter available similar to Equals() method, which helps to compare case insensitive.
Case insensitive containsIndexOf() finds the first occurrence of a particular string inside another string. The comparison type is determined by the StringComparison parameter, which we pass as the second parameter. String. IndexOf() returns the position of the first occurrence of a substring inside a string.
Remarks. The StringComparer returned by the OrdinalIgnoreCase property treats the characters in the strings to compare as if they were converted to uppercase using the conventions of the invariant culture, and then performs a simple byte comparison that is independent of language.
You should use a new HashSet<string>(StringComparer.OrdinalIgnoreCase)
.
Note that this is an unordered set.
You could use a StringDictionary
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With