String.Contains Case Sensitive
String.Contains Case Sensitive
Case Sensitive String.Contain
String.Contains vs IndexOf .Net
I encountered an issue with string contains couple of days ago... well, the fact is - it has no
StringComparison for culture and Case Sensitivity.
I found a better way to do this, and I just wanted to share in a short post:
string bookTitle = "The Old Man and the Sea";
if (bookTitle.IndexOf("the old man") > -1)
{
// this is case sensitive
}
if (bookTitle.IndexOf("the old man", StringComparison.OrdinalIgnoreCase) > -1)
{
// this is ignore case
}
There are some more options in the StringComparison , but I'll leave it to you to play with
Good day,
Elad Shalom,
CTO at ITweetLive.com
Case Sensitive String.Contain
String.Contains vs IndexOf .Net
I encountered an issue with string contains couple of days ago... well, the fact is - it has no
StringComparison for culture and Case Sensitivity.
I found a better way to do this, and I just wanted to share in a short post:
string bookTitle = "The Old Man and the Sea";
if (bookTitle.IndexOf("the old man") > -1)
{
// this is case sensitive
}
if (bookTitle.IndexOf("the old man", StringComparison.OrdinalIgnoreCase) > -1)
{
// this is ignore case
}
There are some more options in the StringComparison , but I'll leave it to you to play with
Good day,
Elad Shalom,
CTO at ITweetLive.com