How do I use indexOf() case insensitively?

asp.net, c#

Solution

You can Use Overloaded Method

IndexOf("punctuation", StringComparison.OrdinalIgnoreCase);

Eg.

List<string> fnColArr = new List<string>() 
{ "Punctuation", "period", "Space", "and", "yes" };

            foreach (string item in fnColArr)
            {
                if (item.IndexOf("puNctuation", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    Console.WriteLine("match");

                }
            }

Problem

I have list of strings: ``` List<string> fnColArr = new List<string>(); fnColArr={"Punctuation,period,Space,and,yes"}; ``` I am using the `IndexOf` property for `List` to find the string in the current list: ``` int arrayval = fnColArr.IndexOf("punctuation"); ``` Now the value of `arrayval` is -1, because the string is not present in the list. But here the only difference is the lower case. I want to also find the string `punctuation`, regardless of its case.

Original source