fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. Console.WriteLine("Testing with 'xxx yy zzzz'");
  10. foreach (var pair in SplitIntoPairsByWhitespace("xxx yy zzzz"))
  11. {
  12. Console.WriteLine(string.Join(", ", pair));
  13. }
  14. Console.WriteLine("Testing with 'a b c d'");
  15. foreach (var pair in SplitIntoPairsByWhitespace("a b c d"))
  16. {
  17. Console.WriteLine(string.Join(", ", pair));
  18. }
  19. }
  20. public static List<string[]> SplitIntoPairsByWhitespace(string text)
  21. {
  22. var chunks = text.Split();
  23. var result = new List<string[]>();
  24. for (var i=0; i<chunks.GetLength(0) - 1; i++)
  25. {
  26. var first = new List<string>();
  27. for (var j=0; j <= i; j++)
  28. first.Add(chunks[j]);
  29. var second = new List<string>();
  30. for (var j=i+1; j < chunks.GetLength(0); j++)
  31. second.Add(chunks[j]);
  32. result.Add(new[] {string.Join(" ", first), string.Join(" ", second)});
  33. }
  34. return result;
  35. }
  36. }
Success #stdin #stdout 0.03s 24816KB
stdin
Standard input is empty
stdout
Testing with 'xxx yy zzzz'
xxx, yy zzzz
xxx yy, zzzz
Testing with 'a b c d'
a, b c d
a b, c d
a b c, d