How to get distinct value from Text File?

I have a text file as below and I want to retrieve distinct value.
The first one email address’s first letter is being capital letter and
The second one email address’s first letter is being small letter.

strEmailAddress.Select(Function(m) m.Value).Distinct()

If I use above code, it retrieved both of them, but I want to get only one due to they’re same email addresses. How can I solve it?

Aaaaaaa@gmail.com*
aaaaaaa@gmail.com*

@myakkhaing

distinctEmails = (From row In yourDataTable.AsEnumerable()
                  Select row.Field(Of String)("EmailAddress").ToLower()).Distinct().ToList()

Please try this linq query in assign activity

Hi @myakkhaing

Check the below expression,

strEmailAddress.Distinct(Function(m) m.Value).Copytodatatable()

Hope it helps!!

It doesn’t work. I am sorry I want to retrieve from text file not from datable.

It doesn’t work. I am sorry I want to retrieve from text file not from datable.

strEmailAddress is the String variable… @myakkhaing

If it’s string variable then how was the input data stored in that variable.

Could you be more specific. Share your input and expected output then we will get to understand.

If you input is like below,

- Assign -> strEmailAddress = "Aaaaaaa@gmail.com
                               aaaaaaa@gmail.com
                               Bbbbbb@gmail.com
                               bbbbbb@email.com"

Then use the below LINQ Expression to get the distinct values,

- Assign -> strDistinctvalues = String.Join(Environment.Newline, strEmailAddress.Split(Environment.NewLine.ToCharArray).Select(Function(X) X.ToString.ToLower).tolist().Groupby(Function(Y) Y.ToString).Select(Function(grp) grp.first).tolist())

Check the below workflow for better understanding,
image

@myakkhaing

emailArray = emailText.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
distinctEmails = (From email In emailArray Select email.ToLower()).Distinct().ToList()
String.Join(Environment.NewLine, distinctEmails)

I am sorry it was hard to understand, Here is my program.
strEmailAddresses is IEnumerable.

strEmailAddressess.GroupBy(Function(m)m.Value).Select(Function(g)g.First).ToArray()

It doesn’t work too.

Okay @myakkhaing

Try the below expression in For each activity,

strEmailAddress.Cast(Of System.Text.RegularExpressions.Match)().Select(Function(X) X.ToString().ToLower().Trim).ToList().GroupBy(Function(Y) Y.ToString()).Select(Function(grp) grp.First()).toarray()

Hope it helps!!

1 Like

@mkankatala
Thank you very much. It perfectly worked. :smiley:

1 Like

It’s my pleasure… @myakkhaing

Happy Automation!!

1 Like

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