Skip to main content
Removed meta commentary and solutions. Solutions go in answers, not in edits to the question.
Source Link
TylerH
  • 21.3k
  • 84
  • 84
  • 121

Case insensitive 'Contains How to make '.Contains(string)' case insensitive

Is there a way to make the following return true?

string title = "ASTRINGTOTEST"; title.Contains("string"); 

There doesn't seem to be an overload that allows me to set the case sensitivity. Currently I UPPERCASE them both, but that's just silly (by which I am referring to the i18n issues that come with up- and down casing).

UPDATE

This question is ancient and since then I have realized I asked for a simple answer for a really vast and difficult topic if you care to investigate it fully.

For most cases, in mono-lingual, English code bases this answer will suffice. I'm suspecting because most people coming here fall in this category this is the most popular answer.

This answer however brings up the inherent problem that we can't compare text case insensitive until we know both texts are the same culture and we know what that culture is. This is maybe a less popular answer, but I think it is more correct and that's why I marked it as such.

Case insensitive 'Contains(string)'

Is there a way to make the following return true?

string title = "ASTRINGTOTEST"; title.Contains("string"); 

There doesn't seem to be an overload that allows me to set the case sensitivity. Currently I UPPERCASE them both, but that's just silly (by which I am referring to the i18n issues that come with up- and down casing).

UPDATE

This question is ancient and since then I have realized I asked for a simple answer for a really vast and difficult topic if you care to investigate it fully.

For most cases, in mono-lingual, English code bases this answer will suffice. I'm suspecting because most people coming here fall in this category this is the most popular answer.

This answer however brings up the inherent problem that we can't compare text case insensitive until we know both texts are the same culture and we know what that culture is. This is maybe a less popular answer, but I think it is more correct and that's why I marked it as such.

How to make '.Contains(string)' case insensitive

Is there a way to make the following return true?

string title = "ASTRINGTOTEST"; title.Contains("string"); 

There doesn't seem to be an overload that allows me to set the case sensitivity. Currently I UPPERCASE them both, but that's just silly (by which I am referring to the i18n issues that come with up- and down casing).

added 5 characters in body
Source Link
Uwe Keim
  • 40.9k
  • 61
  • 193
  • 309

Is there a way to make the following return true?

string title = "ASTRINGTOTEST"; title.Contains("string"); 

There doesn't seem to be an overload that allows me to set the case sensitivity.. Currently I UPPERCASE them both, but that's just silly (by which I am referring to the i18n issues that come with up- and down casing).

UPDATE
This

This question is ancient and since then I have realized I asked for a simple answer for a really vast and difficult topic if you care to investigate it fully.
For

For most cases, in mono-lingual, English code bases this answer will suffice. I'm suspecting because most people coming here fall in this category this is the most popular answer.
  

This answer however brings up the inherent problem that we can't compare text case insensitive until we know both texts are the same culture and we know what that culture is. This is maybe a less popular answer, but I think it is more correct and that's why I marked it as such.

Is there a way to make the following return true?

string title = "ASTRINGTOTEST"; title.Contains("string"); 

There doesn't seem to be an overload that allows me to set the case sensitivity.. Currently I UPPERCASE them both, but that's just silly (by which I am referring to the i18n issues that come with up- and down casing).

UPDATE
This question is ancient and since then I have realized I asked for a simple answer for a really vast and difficult topic if you care to investigate it fully.
For most cases, in mono-lingual, English code bases this answer will suffice. I'm suspecting because most people coming here fall in this category this is the most popular answer.
 This answer however brings up the inherent problem that we can't compare text case insensitive until we know both texts are the same culture and we know what that culture is. This is maybe a less popular answer, but I think it is more correct and that's why I marked it as such.

Is there a way to make the following return true?

string title = "ASTRINGTOTEST"; title.Contains("string"); 

There doesn't seem to be an overload that allows me to set the case sensitivity. Currently I UPPERCASE them both, but that's just silly (by which I am referring to the i18n issues that come with up- and down casing).

UPDATE

This question is ancient and since then I have realized I asked for a simple answer for a really vast and difficult topic if you care to investigate it fully.

For most cases, in mono-lingual, English code bases this answer will suffice. I'm suspecting because most people coming here fall in this category this is the most popular answer. 

This answer however brings up the inherent problem that we can't compare text case insensitive until we know both texts are the same culture and we know what that culture is. This is maybe a less popular answer, but I think it is more correct and that's why I marked it as such.

We should try to aviod "UPDATE" blocks: https://meta.stackexchange.com/a/127655/316262
Source Link
Georg Plaz
  • 6k
  • 5
  • 44
  • 66

Is there a way to make the following return true?

string title = "ASTRINGTOTEST"; title.Contains("string"); 

There doesn't seem to be an overload that allows me to set the case sensitivity.. Currently I UPPERCASE them both, but that's just silly.

UPDATE
The sillyness (by which I referam referring to is the i18n issues that come with up- and down casing).

UPDATE
This question is ancient and since then I have realized I asked for a simple answer for a really vast and difficult topic if you care to investigate it fully.
For most cases, in mono-lingual, English code bases this answer will suffice. I'm suspecting because most people coming here fall in this category this is the most popular answer.
This answer however brings up the inherent problem that we can't compare text case insensitive until we know both texts are the same culture and we know what that culture is. This is maybe a less popular answer, but I think it is more correct and that's why I marked it as such.

Is there a way to make the following return true?

string title = "ASTRINGTOTEST"; title.Contains("string"); 

There doesn't seem to be an overload that allows me to set the case sensitivity.. Currently I UPPERCASE them both, but that's just silly.

UPDATE
The sillyness I refer to is the i18n issues that come with up- and down casing.

UPDATE
This question is ancient and since then I have realized I asked for a simple answer for a really vast and difficult topic if you care to investigate it fully.
For most cases, in mono-lingual, English code bases this answer will suffice. I'm suspecting because most people coming here fall in this category this is the most popular answer.
This answer however brings up the inherent problem that we can't compare text case insensitive until we know both texts are the same culture and we know what that culture is. This is maybe a less popular answer, but I think it is more correct and that's why I marked it as such.

Is there a way to make the following return true?

string title = "ASTRINGTOTEST"; title.Contains("string"); 

There doesn't seem to be an overload that allows me to set the case sensitivity.. Currently I UPPERCASE them both, but that's just silly (by which I am referring to the i18n issues that come with up- and down casing).

UPDATE
This question is ancient and since then I have realized I asked for a simple answer for a really vast and difficult topic if you care to investigate it fully.
For most cases, in mono-lingual, English code bases this answer will suffice. I'm suspecting because most people coming here fall in this category this is the most popular answer.
This answer however brings up the inherent problem that we can't compare text case insensitive until we know both texts are the same culture and we know what that culture is. This is maybe a less popular answer, but I think it is more correct and that's why I marked it as such.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot
Loading
explained why I chose the less popupar answer
Source Link
Boris Callens
  • 93.8k
  • 87
  • 212
  • 311
Loading
I have added string tag as question is related to strings
Link
Loading
Question Protected by Shankar Narayana Damodaran
Copy edited.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134
Loading
Notice removed Canonical answer required by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Notice added Canonical answer required by Colonel Panic
Bounty Started worth 100 reputation by Colonel Panic
added 181 characters in body; edited tags
Source Link
Boris Callens
  • 93.8k
  • 87
  • 212
  • 311
Loading
refined test code
Source Link
Boris Callens
  • 93.8k
  • 87
  • 212
  • 311
Loading
Source Link
Boris Callens
  • 93.8k
  • 87
  • 212
  • 311
Loading