List.IndexOf case insensitive, trim whitespace

Hi, I am currently using the method list.IndexOf(“string”) to find the index of an item with a certain value. How do I modify this so that it matches even if the string is case insensitive and contains whitespace? E.g. “String”, “sTring”, " stRing" etc

@DEATHFISH

is this what you are looking for?

getIndexOfString.xaml (5.9 KB)

@rahatadi

Sorry, what I am looking for is that I have a List of String, and I want to find the index of a certain string value within that list. It should return the index regardless of whether the List item has different case or has whitespace.

@DEATHFISH

Lets say you have list called l1

String.join(" ",l1.toarray) and use this in above solution.

Do you have a solution which uses Lambda expressions or LINQ? Thanks

Preferably need to assign the boolean within one activity

@DEATHFISH

At your service sir.:slight_smile:

l1.FindIndex(Function(x) x.Equals(“yourStringHere”, StringComparison.OrdinalIgnoreCase))

Hi, does this work even with whitespace?

@DEATHFISH
Give this a try

@rahatadi

Doesn’t work… it keeps returning -1

The full expression is dataRow.ItemArray.ToList.FindIndex(Function(x)…)

When I use dataRow.ItemArray.ToList.IndexOf it works but when I use the Lambda expression it does not…

I am using the same find string in FindIndex(Function(x) x.Equals(“Field”, …)) as I am using in IndexOf(“Field”)

@rahatadi What could be causing it not to work?

@DEATHFISH

Is it datarow?
Then
L1.findIndex(function(x) x(“fieldname”).equals(“yourStringHere”, StringComparison.OrdinalIgnoreCase))
Or
Could you please post simplified version of your code?

@rahatadi

Hi, it is a DataRow but it does not have column names so I have to convert it to List first before using FindIndex and find by value… x(“fieldname”) cannot be used in this case

@DEATHFISH

could you please upload simplified version of your workflow?

@rahatadi Hi, i need to pick all the string in array irresepective of case. I have a string name in samll case in config. But when i pick in array of string, i should pick even if it uppercase or mixed case.So how to use the ordinal ignore case here??