Retrieving a index of an array as a variable to be used dynamically inside a replace activity

Ok, here it goes.

I have a string called fileName which is dynamic. I want to see if it contains a string from an array called arrayOfStrings and if so grab the corresponding string from the array either by using IndexOf or creating a variable with the string in it. Then from there, using that variable as a dynamic variable in my replace activity.

fileName = “This is a string with the number one”
arrayOfStings = {“One”, “Two”, “Three”)
I want to be able to find something as follows;
If fileName.Contains(arrayOfStings, IndexOf array()) or something like that
Then assign the output to a variable such as arrayPulledIndex = arrayOfString.IndexOf.toString?
So the resulting variable would = “One”
Then I want to use that variable inside the new handy replace tool and set the Value to the new variable. From what I’ve played around with so far I don’t know if this is even possible in the activity.

The reason I’m doing this is I’m just trying to clean up some code. I know there is a better way then doing a bunch of if statements searching for sting.contains for each item. I’m attaching a visual to maybe help you all out

Any help with this would be greatly appreciated

@BotMonkey Will the Input String Contain two or more values from the String Array ?

@supermanPunch It will not

@BotMonkey Can you Try this :

foundString = arrayOfStings.Where(Function(x)fileName.ToString.ToLower.Contains(x.ToLower.Trim)).Select(Function(y)y.ToString)(0)


I’ll have to check in the morning. Bed time here

1 Like

So, it works, but it is also coming up with some null values. Any thoughts?

@BotMonkey What do you mean by null values :sweat_smile: