See if string is inside array of strings (Case insensitive)


I have an array of strings called TestArray and I want to see if a string, let’s call it TestString is inside TestArray (Case insensitive). If the TestString is inside the TestArray, I want to get the array index. How can I do this?

I noticed that there is a post about case insensitive .Contains method, (, but I didn’t find it very helpful…

array.Contains("str", StringComparer.OrdinalIgnoreCase)
1 Like

@Hisuhong Try This :
strArray.IndexOf(strArray, “ValueToFind”)

This will return an Integer which is the Index

Thank you!!!

1 Like

When using Array.IndexOf, is there a way of making the ValueToFind case insensitive as well?

@Hisuhong If you want to Check for case Insensitive as well, you can use this :
string.join(" “,strArray).ToString.ToLower.Split().IndexOf(string.join(” ",strArray).ToString.ToLower.Split(),“ValueToFind”.tolower)

This Expression will Join the String Array Variable first to convert it to String, then it will convert it into Lower Case, then it will get converted to String Array again and it will check “ValueToFind” is present in it and will return the index if Present

@supermanPunch when I do this, it gives me “-1” as the index :sweat_smile:

@supermanPunch nevermind I figured it out. Thank you for your help!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.