Falcon Falcon - 1 year ago 93
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download