fork download
  1. using static System.Console;
  2. using static System.Convert;
  3. using System.Text;
  4.  
  5. public class Test {
  6. public static void Main() {
  7. WriteLine(WrapString("0123456789012345678901234567890123456789", 10));
  8. WriteLine(WrapString("01234567890123456", 10));
  9. WriteLine(WrapString("012345", 10));
  10. }
  11.  
  12. static string WrapString(string text, int len) {
  13. if (text.Length <= len) return text;
  14. var sb = new StringBuilder(text.Length + text.Length / len * 2);
  15. var i = 0;
  16. for (; i < text.Length / 10; i++) {
  17. sb.Append(text[(i * 10)..(i * 10 + 10)]);
  18. sb.Append("\r\n");
  19. }
  20. if (text.Length / 10 != ToSingle(text.Length) / 10) {
  21. sb.Append(text[(i * 10)..]);
  22. sb.Append("\r\n");
  23. } else sb.Remove(sb.Length - 2, 2);
  24. return sb.ToString();
  25. }
  26. }
  27.  
  28. //https://pt.stackoverflow.com/q/228864/101
Success #stdin #stdout 0.05s 24648KB
stdin
Standard input is empty
stdout
0123456789
0123456789
0123456789
0123456789
0123456789
0123456

012345