fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string string1 = "quick brown fox jumps over the lazy dog";
  9. foreach (var strSection in string1.SplitInto(8))
  10. Console.WriteLine("'{0}'", strSection);
  11. }
  12. }
  13. public static class MyExtensions
  14. {
  15. public static IEnumerable<string> SplitInto(this string value, int size)
  16. {
  17. for (int i = 0; i < value.Length; i += size)
  18. {
  19. if (i + size <= value.Length)
  20. yield return value.Substring(i, size);
  21. else
  22. yield return value.Substring(i);
  23. }
  24. }
  25. }
Success #stdin #stdout 0.02s 34728KB
stdin
Standard input is empty
stdout
'quick br'
'own fox '
'jumps ov'
'er the l'
'azy dog'