How to check repeated letters in a string c#

前端 未结 10 593
太阳男子
太阳男子 2020-12-21 01:39

I am creating a program that checks repeated letters in a string.

For Example:

wooooooooooow
happpppppppy

This is my

10条回答
  •  渐次进展
    2020-12-21 01:48

    To find duplicate or repeated letters in given string using C#

    string str = "Welcome Programming";
    char[] Array = str.ToCharArray();
    var duplicates = Array.GroupBy(p => p).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
    string duplicateval= string.Join(",", duplicates.ToArray());
    

    Output:

    e,o,m,r,g

提交回复
热议问题