Falcon Falcon - 3 months ago 12
C# Question

Find a substring in a case-insensitive way - C#

Possible Duplicate:

Case insensitive contains(string)

method of String class a substring can be found.
How to find a substring in a string in a case-insensitive manner?


You can use the IndexOf() method, which takes in a StringComparison type:

string s = "foobarbaz";
int index = s.IndexOf("BAR", StringComparison.CurrentCultureIgnoreCase); // index = 3

If the string was not found, IndexOf() returns -1.