How to make Contains(string) method case-insensitive in C#?
Hello everyone! I'm a beginner C# developer, I've encountered a problem that seems simple, but I can't find the right solution.
I have a list of strings, and I want to check if each string contains a specific word. The problem is that the Contains() method is case-sensitive by default. For example, I have this code:
```csharp
string text = "Hello, World!";
bool result = text.Contains("world"); // returns false, even though the word "World" is present
```
I want the search to work regardless of the case of the searched word. I tried using ToLower() or ToUpper(), but it looks hacky and ugly:
```csharp
bool result = text.ToLower().Contains("world".ToLower());
```
Also, I've heard that this can lead to performance issues and with different
No answers yet.
Log in to leave an answer