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.
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");
}
}
Alternatively, you could also use a lambda function
fnColArr.FindIndex(x => x.ToLower().Equals("punctuation"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With