fork(1) download
  1. using System;
  2. using System.Text;
  3.  
  4. public class Test
  5. {
  6. public static string SplitToLines(string str, int n)
  7. {
  8. var sb = new StringBuilder(str.Length + (str.Length + 9) / 10);
  9.  
  10. for (int q=0; q<str.Length; )
  11. {
  12. sb.Append(str[q]);
  13.  
  14. if (++q % n == 0)
  15. sb.AppendLine();
  16. }
  17.  
  18. if (str.Length % n == 0)
  19. --sb.Length;
  20.  
  21. return sb.ToString();
  22. }
  23.  
  24. public static void Main()
  25. {
  26. Console.WriteLine("{0}", SplitToLines("0123456789qwertyuiop[]asdfghjkl;'zxcvbnm", 10));
  27. Console.WriteLine("==========");
  28. Console.WriteLine("{0}", SplitToLines("0123456789qwertyuiop[]asdfghjkl;'zxcvbnmzxc", 10));
  29. Console.WriteLine("==========");
  30. Console.WriteLine("{0}", SplitToLines("0123456789", 10));
  31. Console.WriteLine("==========");
  32. Console.WriteLine("{0}", SplitToLines("01234567", 10));
  33. Console.WriteLine("==========");
  34. }
  35. }
Success #stdin #stdout 0.01s 131648KB
stdin
Standard input is empty
stdout
0123456789
qwertyuiop
[]asdfghjk
l;'zxcvbnm
==========
0123456789
qwertyuiop
[]asdfghjk
l;'zxcvbnm
zxc
==========
0123456789
==========
01234567
==========