Find duplicate alphabets and their count in string UiPath
Sometimes we need to check the duplicate alphabets and their count in some of the cases.
But it is rare care that is implemented in real-time but this could be helpful to understand how we can achieve this task.
Let’s see the practical implementation of this task.
Step1: Drag and Drop an assign activity from activities panel to the designer panel and create a string variable with the value as shown below:
Here we have a string variable that is RPA LEARNERS.
We need to find how many duplicate alphabets are present in this string variable.
Step2: Drag and Drop an assign activity from the activity panel to the designer panel as shown below:
Here we are using a LINQ query instead of using if condition and or loops.
Let’s see what we are doing there in the query:
Firstly we are converting the string variable to a List and then getting the distinct values from that list that is created from the string.
In the second one, we are doing the same but not the distinct values we are comparing the first character and getting the count of that alphabets and converting them to a list.
We also need to create a list of a string variable to hold these values as shown above.
Step3: Drag and Drop a for each activity from the activities panel to the designer panel as shown below:
It will provide you with each alphabet and the count of this as shown below:
But if you want every duplicate alphabet and their count in a single variable then you can use the code that is shown below:
Here we can see each alphabet in our string variable ‘RPA LEARNERS’ is here with how many times it is repeated in that RPA LEARNERS.