How to remove duplicates in string using linq .also count the number of characters that gets repeated

Expected output:
Output_str=“Tharni” and T-1,H-1,A-2,R-2,N-1,I-1

Please help

Hi @tharani.natarajan,

Please find the XAML file which performs the logic which you have asked for.
Use this LINQ,
For this Output: T-1,H-1,A-2,R-2,N-1,I-1, this Linq is:
(From x In strName.ToArray.distinct Select c = x.ToString & "-" & (from x2 in strName.ToArray where x2=x).count).ToArray

For This Output: Tharni (Unique Characters in the String), the Linq is:
String.Join("",(From x In strName.ToArray.distinct Select c = x.ToString).ToArray)

For printing this value, one by one I have used a for each activity.
Sample Output

image (2.5 KB)

I hope this would solve your query✌️.

Kindly mark as solution if you’re query is solved


1 Like


FYI, another solution:

strResult = String.Join("",yourString.Select(Function(c) c.ToString).Distinct(StringComparer.InvariantCultureIgnoreCase))

arrResult = yourString.GroupBy(Function(c) c.ToString().ToUpper).Select(Function(g) g.Key+"-"+g.Count.ToString()).ToArray()

Sequence3.xaml (6.3 KB)


1 Like

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