I have a list that contains 4,4,0,1 . When i use IndexOf(4) it only give me the first index which is 0. I also want to get that second position of the 4. How can i go about?
Hey,
you can iterate from List using for each Activity
Regards
Rounak
Hi! even if so, indexOf(4) will always give me a position of 0 because it will stop at the first occurrence of my list which is 4,4,0,1. I do wan to get the position of my second ‘4’
Do you have any idea of what method i can use?
Assign Activity
arrIndex | Int32 Array =
Enumerable.Range(0,Numbers.Count).Where(Function (x) Numbers.ElementAt(x) = 4 ).ToArray
Hi Peter,
Thanks for helping… Im not used to LINQ … Do you mind explaining how to use it?
we are creating a sequence with the indexes
then we loop over it and filter out where the condition is met
ah i get it but i cant seem to build it from uipath
thats all
IndexOf function ONLY returns the 1st occurrence. Using linq as shown by @ppr is probably the fastest way to go about it, and will also enable you to learn more linq in the future as it comes in handy all the time!
Thanks! one question here my list is actually List. will it work the same way?
String list
not clear with your question
datetype = list: yes it should work
variable name = list. we would recommend not using class names as variable names
but when changing the variable name to your variable name it should work
with following statement you can also check within the immediate panel
Enumerable.Range(0, yourListVar.Count).Where(Function (x) YourListVar(x).Equals(4)).toArray
toList when a list is to return
Enumerable.Range(0, yourListVar.Count).Where(Function (x) YourListVar(x).Equals(4.toString)).toArray
Thank you!!! Seems like is only getting the last index of its occurrence like 4401 index of 4 is 1. I think i might have explain it wrongly at the start… Sorry for that but my expected results should be like this 4,0 4,1,0,2,0,3 where it captures the index of the position… So far IndexOf doesn’t achieve the results…
se just recap and re-define your requirement clear and precise
share with us input sample and expected output along with description
Just keep in mind
here we do need more clearness as e.g. the expected datatype / output is not mentioned
Also have a look on this: