I have an array of 15 items in it I want to loop through it and get the matched 10 items.here problem Iam facing is first item is matched at 6th index of input and second item was checking from 7th index of input.how to get all the matched values
Welcome to the community
May I know what is the match criteria that you are using? And array is immutable so convert to list and try or append to list would help and then at last can convert to array again
You can try this
- Initialize a list L1
- For loop on array A1 and type argument to string in for loop propwrties
- If condition to check
currentitem.Contains("cyz")
- On then side use append item to list and append currentitem to L1
- Outside loop L1.ToArray() to convert
Else using linq
Arr = arr.ToList.Where(function(x) x.Contains("xyz")).ToArray
Hope this helps
Cheers
Cheers
Welcome to forums
Can you tell me how you are getting the 10 items? what is the variable type
Can you give some sample Input and required output?
Thanks,
Srini
I have a parentfolder in which i have 15 sub folders
I neeed to extract all the subfolders titles first and i will get a input from gettext and finds the match with the subfolders titles.
Process of getting input values from the get text will continued upto 10 values.after completion of each input
- Firstly you can initialize an array variable to store the matched items. Eg:- âarrItemsMatchâ
- Use a âFor Eachâ loop activity to iterate through each item in your input array.
- Inside the loop, use an âIfâ activity to check if the current item matches your criteria. If the item matches, add it to the
arrItemsMatch
array using the âAdd To Collectionâ activity. - After the loop completes, the
arrItemsMatch
array will contain all the items that matched your criteria. - You can then use the
arrItemsMatch
array as needed in your subsequent UiPath activities, such as writing the matched items to a CSV file, performing further processing, or displaying the matched items in a message box.
Thanks!!
Okay, another way to solve is that
- You have the string value of the Parentfolder and 15 sub folders file Name
- Declare another String variable as Matches
- Use Get Text activity and you need to use If condition as stringvariable.Contains(GetTextValue)
- If true then write as Matches.Append(GetTextValue).ToArray
Hope this may help you
Thanks,
Srini
Hi @Shiva_Nikhil - Try below methods
Method1
- Read the folder names into an array (variable name say FolderName)
- Take while loop, and keep the condition as 1<=10(1 should be stored in a variable say Counter, this increments every time), as youâll get 10 different values using Get Text
- Within this loop, use For Each to loop through each folder, take If condition within the same loop (For Each) to validate the Get Text output matches with any folder name
- If matches, do the required options, then break the For Each loop using Break activity
- This way, the while loops for 10 times, and each extracted value using Get Text can validate with all folder names
- Increment counter variable, it loops back and repeat the actions
Method2:
- Read the folder names into an array (variable name say FolderName)
- Take while loop, and keep the condition as 1<=10 (1 should be stored in a variable say Counter, this increments every time), as using Get Text youâll get 10 different values
- Within this loop, instead of For Each you can simply take If condition,
FolderName.contains(GetTextOutput)
Then > Do required actions
Else > Do required actions
FolderName is the array variable that has folder names within the parent folder
- Increment counter variable, it loops back and repeat the actions until the while condition become false
Thanks alot