cancel
Showing results for 
Search instead for 
Did you mean: 

how to print duplicate characters in string?

Haribp
Level 3

I have string strInput="Characters", i need to print only duplicates characters from string,
so strOutput="car"

How to do it? please help me.



------------------------------
Hari bp
------------------------------
3 REPLIES 3

Devendra_KumarP
Level 7
Hi Hari, 

Write the Regex Expression for this. let me know if you need help from me.

------------------------------
Devendra Kumar Prajapati
RPA Manager
Infosys
Chandigarh, India
------------------------------
Devendra Kumar Prajapati RPA Manager Infosys Chandigarh, India

Hi Sai,

You can use a combination of actions like 'Utility - Strings' and 'Utility - Collection Manipulation' to get the duplicate characters:

12207.png
I can explain you the working of the workflow here:

1) First, I used the 'Split Text By Lines' action of the 'Utility - Strings' with the following input parameters:

12208.png

This will give you list of characters in different rows as shown below:

12209.png
Once, you got this collection we would iterate through this collection using a loop stage. Now create a predefined collection called 'Results' with following schema:
12211.png

Now, we will check if the current character value in the Split Values collection exists in the Results collection or not using the 'Collection Contains Value' action from 'Utility - Collection Manipulation'. It will return a flag called 'Character Available' which we will check using a decision stage and if the value is True we would skip the current iteration and if the value is False we would proceed ahead. This decision tells us if the Results collection already has that unique character with the occurrence value or not.

12212.png
12213.png


If the value of the flag is False, we would set two data items called as 'Current Character' (Text) and 'Occurrence' (Number) with the following calculation stages:

12214.pngThe logic here is pretty simple: for current character we would simply set up the current character row which we are getting from 'Split Values' collection whereas for the occurrence we will use the logic as:

Len(Lower([Test String])) - Len(Replace(Lower([Test String]),[Split Values.Line Text],"")) / Len([Split Values.Line Text])​

What it does is let say you have a word called as 'Apple' and we need to get the occurrence of the letter 'p' so we first take the length of the word 'Apple' which is 5 and the we replace the letter 'p' with blank in that word so that the word becomes 'Ale' and then we get the length of the resultant word which is 3. So now we take the difference between the lengths which is 5-3 = 2 and we divide this by the length of the letter which we need to find the occurrence for that is 'p' which will be 1.

Hence, the occurrence is equal to 2/1 = 2 so 'p' occurs 2 times in the word 'Apple'

Now we will simply add the row to 'Results' collection and set up these two calculated values:

12215.png12216.png

So now you will end up with a collection called 'Results ' at the end of the loop stage which looks like this:

12217.png
Now we can use the 'Filter Collection' action from 'Utility - Collection Manipulation' and use the following filter query:

"[Occurrence] > 1"​


12218.pngNow you will get a collection called 'Filtered Results' with the following values:

12219.png
So this is basically the letters which are occurring more than one time in our word. Now you can simply iterate through this collection and set up a blank data item of text type called 'Joined Text' with all these letters:

12220.png
12221.png

Hence, at the end of the loop stage you will get the result as:

12222.png

You can refer to the attached process for more details:


------------------------------
----------------------------------
Hope it helps you out and if my solution resolves your query, then please mark it as the 'Best Answer' so that the others members in the community having similar problem statement can track the answer easily in future

Regards,
Devneet Mohanty
Intelligent Process Automation Consultant | Sr. Consultant - Automation Developer,
Wonderbotz India Pvt. Ltd.
Blue Prism Community MVP | Blue Prism 7x Certified Professional
Website: https://devneet.github.io/
Email: devneetmohanty07@gmail.com

----------------------------------
------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Hope this helps you out and if so, please mark the current thread as the 'Answer', so others can refer to the same for reference in future.
Regards,
Devneet Mohanty,
SS&C Blueprism Community MVP 2024,
Automation Architect,
Wonderbotz India Pvt. Ltd.

NaveenRPA
Level 4
Hi Hari 

We can get duplicates chars from string without using Regex, Object and Code Stage.

By using Left, Right, Replace and Len function we can get duplicate chars from string.

12225.png


------------------------------
naveen k
------------------------------