Iam anable to get the matched items

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

@Shiva_Nikhil

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

  1. Initialize a list L1
  2. For loop on array A1 and type argument to string in for loop propwrties
  3. If condition to check currentitem.Contains("cyz")
  4. On then side use append item to list and append currentitem to L1
  5. Outside loop L1.ToArray() to convert

Else using linq

Arr = arr.ToList.Where(function(x) x.Contains("xyz")).ToArray

Hope this helps

Cheers

Cheers

@Shiva_Nikhil

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

Hi @Shiva_Nikhil

  1. Firstly you can initialize an array variable to store the matched items. Eg:- ‘arrItemsMatch’
  2. Use a “For Each” loop activity to iterate through each item in your input array.
  3. 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.
  4. After the loop completes, the arrItemsMatch array will contain all the items that matched your criteria.
  5. 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!!

@Shiva_Nikhil

Okay, another way to solve is that

  1. You have the string value of the Parentfolder and 15 sub folders file Name
  2. Declare another String variable as Matches
  3. Use Get Text activity and you need to use If condition as stringvariable.Contains(GetTextValue)
  4. 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

Thanks alot Nitya

2 Likes