Getting distinct value in string

Hi,

I have a string variable with a value of “Manager 11Manager 11”.

string = Manager 11Manager 11

I wanted to get only the “Manager 11” value. How should I do it?

I tried using this formula but the output was incorrect:
String.Join(" ", text.Distinct())

Output: “M a n g e r 1”

Note that there are cases that it will only be “Manager 11” so it should stay as is. No need to trim it anymore. I am looking for a code that can be used for both scenarios.

Let’s say the text is “Manager 11”, even if I use the code, the output will still be “Manager 11” but if the text is “Manager 11Manager 11”, the output should also be “Manager 11”.

Thank you.

  1. Split by space
  2. use 0 and 2 index of array
  3. Concat them with space
    test=“Manager 11Manager 11”
    strAry=test.split(" “c)
    test=strAry(0)+” "+strAry(2)

But there’s also a scenario which is a date like “03/02/202103/02/2021” wherein I only need to get “03/02/2021”

Take string count and divide by 2 and use a substring

Hi @Veena
Try this workflow
Main.xaml (9.3 KB)

I had used the concept of regex to get the data

Mark it as solution if it resolves your query

Regards
Nived N
Happy Automation

Thanks for this. It’s working now.

1 Like

Hi, Lakshay gave me the solution I was looking for but will also check your approach. Thank you.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.