fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string str = "qwe rty uiop sdfasdfad dfafsa";
  9.  
  10. Func<String, Char, String> agg =
  11. ((s, c) => Char.IsWhiteSpace(c) && s.Last() == c ? s : s + c);
  12. var chars = str.Aggregate("", agg);
  13. Console.WriteLine(string.Join("", chars));
  14.  
  15. str = string.Join("", str.Where(c => !Char.IsWhiteSpace(c)));
  16. Console.WriteLine(str);
  17. }
  18. }
Success #stdin #stdout 0.03s 24240KB
stdin
Standard input is empty
stdout
qwe rty uiop sdfasdfad dfafsa
qwertyuiopsdfasdfaddfafsa