code_junkie

How do I get an array of repeated characters from a string using LINQ?

Nov 12th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. string s = "abcdefghab";
  2.  
  3. s.ToCharArray().OrderBy(a => a)...
  4.  
  5. String text = "dssdfsfadafdsaf";
  6. var repeatedChars = text.ToCharArray().GroupBy(x => x).Where(y => y.Count() > 1).Select(z=>z.Key);
  7.  
  8. string theString = "abcdefghab";
  9.  
  10. //C# query syntax
  11. var qry = (from c in theString.ToCharArray()
  12. group c by c into g
  13. where g.Count() > 1
  14. select g.Key);
  15.  
  16. //C# pure methods syntax
  17. var qry2 = theString.ToCharArray()
  18. .GroupBy(c => c)
  19. .Where(g => g.Count() > 1)
  20. .Select(g => g.Key);
  21.  
  22. var qry = (from c in theString
  23. group c by c into g
  24. where g.Count() > 1
  25. select g.Key);
Add Comment
Please, Sign In to add comment