C# - Case-insensitive IndexOf method

By [)ia6l0 iii

The IndexOf method in C# is case -sensitive. However, you can use the CompareInto class to make it insensitive to case.

string firstString = ""What a day this has been!"";
string secondString = ""Day"";

CompareInfo sampleCInfo = CultureInfo.InvariantCulture.CompareInfo;
int index = sampleCInfo.IndexOf( firstString, secondString, CompareOptions.IgnoreCase );

Related FAQs

You can read a text file into a string. But practically speaking, not sure why one would do this.
Use the Environment class to get important and user-specific properties like the User Profile folder.
Extension method to check if a substring exists in a string using Regular Expressions
The CaseInsensitiveComparer compares the strings ignoring the case in strings
Use the VittualPathUtility class's ToAbsolute method to convert a virtual path to absolute path
For e.g.
C# - Case-insensitive IndexOf method  (3628 Views)