title: Split a string after a word with up to 20 characters on a line
body: <p>I am trying to write a program which will split a user input of a very long sentence which every 20 characters, a new line is created. If the end of the 20 characters is in the middle of a word, it will print the previous full word</p>
  <pre><code>using System;
  
  namespace stringToLines
  {
      class Program
      {
          static void split()
          {
              string sent = Console.ReadLine();
              int a = sent.Length / 20;
              string[] line;
  
              int space = sent.IndexOf(' ');
              while (space &lt; 20)
              {
                  int i = 0;
                  line[i] = sent.Substring(0, space);
                  sent = sent.Substring(space, sent.Length-space);
                  space = sent.IndexOf(' ');
                  i++;
              }
              for (int i = 0; i &lt;=a; i++)
              {
                  Console.WriteLine(line[i],&quot;\n&quot;);
              }
              Console.ReadLine();
              return split;
          }
          static void Main(string[] args)
          {
              Console.WriteLine(&quot;Please enter your long sentence(&gt;20 characters)&quot;);
  
              split();
          }
      }
  }
  </code></pre>