How to make String.Contains case insensitive?
January 04, 2014 by Anuraj
.Net .Net 3.0 / 3.5 .Net 4.0 ASP.Net Windows Forms
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.
If you run the following tests, TestStringContains2() will fail.
Other option is using like this.
And here is the case insensitive contains method implementation.
And here is the modified tests.
And here is the tests running
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub